pyogrio 0.8.0__cp39-cp39-win_amd64.whl → 0.10.0__cp39-cp39-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 (103) hide show
  1. pyogrio/__init__.py +33 -22
  2. pyogrio/_compat.py +7 -1
  3. pyogrio/_env.py +4 -6
  4. pyogrio/_err.c +460 -445
  5. pyogrio/_err.cp39-win_amd64.pyd +0 -0
  6. pyogrio/_geometry.c +645 -612
  7. pyogrio/_geometry.cp39-win_amd64.pyd +0 -0
  8. pyogrio/_io.c +7764 -7602
  9. pyogrio/_io.cp39-win_amd64.pyd +0 -0
  10. pyogrio/_ogr.c +601 -609
  11. pyogrio/_ogr.cp39-win_amd64.pyd +0 -0
  12. pyogrio/_version.py +3 -3
  13. pyogrio/_vsi.c +7570 -2514
  14. pyogrio/_vsi.cp39-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 +75 -90
  55. {pyogrio-0.8.0.dist-info → pyogrio-0.10.0.dist-info}/WHEEL +1 -1
  56. pyogrio.libs/.load-order-pyogrio-0.10.0 +18 -0
  57. pyogrio.libs/{Lerc-62a2c1c74500e7815994b3e49b36750c.dll → Lerc-089e3fef3df84b17326dcddbf1dedaa4.dll} +0 -0
  58. pyogrio.libs/{gdal-2bfc6a9f962a8953b0640db9a272d797.dll → gdal-debee5933f0da7bb90b4bcd009023377.dll} +0 -0
  59. pyogrio.libs/{geos-289d7171bd083dfed1f8a90e4ae57442.dll → geos-ace4c5b5c1f569bb4213e7bbd0b0322e.dll} +0 -0
  60. pyogrio.libs/{geos_c-2a12859cd876719c648f1eb950b7d94c.dll → geos_c-7478ca0a86136b280d9b2d245c6f6627.dll} +0 -0
  61. pyogrio.libs/geotiff-c8fe8a095520a4ea4e465d27e06add3a.dll +0 -0
  62. pyogrio.libs/{iconv-2-f2d9304f8dc4cdd981024b520b73a099.dll → iconv-2-27352d156a5467ca5383d3951093ea5a.dll} +0 -0
  63. pyogrio.libs/{jpeg62-a67b2bf7fd32d34c565ae5bb6d47c224.dll → jpeg62-e56b6f95a95af498f4623b8da4cebd46.dll} +0 -0
  64. pyogrio.libs/{json-c-79a8df7e59952f5c5d594620e4b66c13.dll → json-c-c84940e2654a4f8468bfcf2ce992aa93.dll} +0 -0
  65. pyogrio.libs/libcurl-d69cfd4ad487d53d58743b6778ec85e7.dll +0 -0
  66. pyogrio.libs/{libexpat-fa55f107b678de136400c6d953c3cdde.dll → libexpat-6576a8d02641b6a3dbad35901ec200a7.dll} +0 -0
  67. pyogrio.libs/liblzma-9ee4accb476ec1ae24e924953140273d.dll +0 -0
  68. pyogrio.libs/{libpng16-6227e9a35c2a350ae6b0586079c10b9e.dll → libpng16-7c36142dda59f186f6bb683e8dae2bfe.dll} +0 -0
  69. pyogrio.libs/{msvcp140-46db46e967c8db2cb7a20fc75872a57e.dll → msvcp140-98b3e5b80de1e5e9d1703b786d795623.dll} +0 -0
  70. pyogrio.libs/proj-a408c5327f3fd2f5fabe8c56815beed7.dll +0 -0
  71. pyogrio.libs/{qhull_r-d8840f4ed1f7d452ff9a30237320bcfd.dll → qhull_r-516897f855568caab1ab1fe37912766c.dll} +0 -0
  72. pyogrio.libs/sqlite3-9bc109d8536d5ed9666332fec94485fc.dll +0 -0
  73. pyogrio.libs/{tiff-ffca1ff19d0e95dad39df0078fb037af.dll → tiff-9b3f605fffe0bccc0a964c374ee4f820.dll} +0 -0
  74. pyogrio.libs/{zlib1-aaba6ea052f6d3fa3d84a301e3eb3d30.dll → zlib1-e5af16a15c63f05bd82d90396807ae5b.dll} +0 -0
  75. pyogrio/_err.pxd +0 -4
  76. pyogrio/_err.pyx +0 -250
  77. pyogrio/_geometry.pxd +0 -4
  78. pyogrio/_geometry.pyx +0 -129
  79. pyogrio/_io.pxd +0 -0
  80. pyogrio/_io.pyx +0 -2738
  81. pyogrio/_ogr.pxd +0 -441
  82. pyogrio/_ogr.pyx +0 -346
  83. pyogrio/_vsi.pxd +0 -4
  84. pyogrio/_vsi.pyx +0 -140
  85. pyogrio/arrow_bridge.h +0 -115
  86. pyogrio/gdal_data/bag_template.xml +0 -201
  87. pyogrio/gdal_data/gmlasconf.xml +0 -169
  88. pyogrio/gdal_data/gmlasconf.xsd +0 -1066
  89. pyogrio/gdal_data/netcdf_config.xsd +0 -143
  90. pyogrio/gdal_data/template_tiles.mapml +0 -28
  91. pyogrio/tests/fixtures/test_datetime.geojson +0 -7
  92. pyogrio/tests/fixtures/test_datetime_tz.geojson +0 -8
  93. pyogrio/tests/fixtures/test_fgdb.gdb.zip +0 -0
  94. pyogrio/tests/fixtures/test_nested.geojson +0 -18
  95. pyogrio/tests/fixtures/test_ogr_types_list.geojson +0 -12
  96. pyogrio-0.8.0.dist-info/DELVEWHEEL +0 -2
  97. pyogrio.libs/.load-order-pyogrio-0.8.0 +0 -18
  98. pyogrio.libs/geotiff-d1c0fcc3c454409ad8be61ff04a7422c.dll +0 -0
  99. pyogrio.libs/libcurl-7fef9869f6520a5fbdb2bc9ce4c496cc.dll +0 -0
  100. pyogrio.libs/liblzma-5a1f648afc3d4cf36e3aef2266d55143.dll +0 -0
  101. pyogrio.libs/proj-74051a73897c9fa6d7bfef4561688568.dll +0 -0
  102. pyogrio.libs/sqlite3-fe7a86058d1c5658d1f9106228a7fd83.dll +0 -0
  103. {pyogrio-0.8.0.dist-info → pyogrio-0.10.0.dist-info}/top_level.txt +0 -0
pyogrio/_err.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"
@@ -1534,7 +1536,7 @@ static const char *__pyx_f[] = {
1534
1536
  /*--- Type declarations ---*/
1535
1537
  struct __pyx_opt_args_7pyogrio_4_ogr_get_string;
1536
1538
 
1537
- /* "pyogrio/_ogr.pxd":441
1539
+ /* "pyogrio/_ogr.pxd":452
1538
1540
  *
1539
1541
  *
1540
1542
  * cdef get_string(const char *c_str, str encoding=*) # <<<<<<<<<<<<<<
@@ -3271,7 +3273,7 @@ static PyObject *__pyx_pf_7pyogrio_4_err_14CPLE_BaseError_2__str__(CYTHON_UNUSED
3271
3273
  PyObject *__pyx_t_1 = NULL;
3272
3274
  PyObject *__pyx_t_2 = NULL;
3273
3275
  PyObject *__pyx_t_3 = NULL;
3274
- int __pyx_t_4;
3276
+ unsigned int __pyx_t_4;
3275
3277
  int __pyx_lineno = 0;
3276
3278
  const char *__pyx_filename = NULL;
3277
3279
  int __pyx_clineno = 0;
@@ -3445,7 +3447,7 @@ static PyObject *__pyx_pf_7pyogrio_4_err_14CPLE_BaseError_4__unicode__(CYTHON_UN
3445
3447
  PyObject *__pyx_t_2 = NULL;
3446
3448
  PyObject *__pyx_t_3 = NULL;
3447
3449
  PyObject *__pyx_t_4 = NULL;
3448
- int __pyx_t_5;
3450
+ unsigned int __pyx_t_5;
3449
3451
  int __pyx_lineno = 0;
3450
3452
  const char *__pyx_filename = NULL;
3451
3453
  int __pyx_clineno = 0;
@@ -3717,6 +3719,7 @@ static CYTHON_INLINE PyObject *__pyx_f_7pyogrio_4_err_exc_check(void) {
3717
3719
  PyObject *__pyx_t_18 = NULL;
3718
3720
  PyObject *__pyx_t_19 = NULL;
3719
3721
  PyObject *__pyx_t_20 = NULL;
3722
+ unsigned int __pyx_t_21;
3720
3723
  int __pyx_lineno = 0;
3721
3724
  const char *__pyx_filename = NULL;
3722
3725
  int __pyx_clineno = 0;
@@ -4048,7 +4051,7 @@ static CYTHON_INLINE PyObject *__pyx_f_7pyogrio_4_err_exc_check(void) {
4048
4051
  __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_CPLE_BaseError); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 167, __pyx_L1_error)
4049
4052
  __Pyx_GOTREF(__pyx_t_11);
4050
4053
  __pyx_t_20 = NULL;
4051
- __pyx_t_12 = 0;
4054
+ __pyx_t_21 = 0;
4052
4055
  #if CYTHON_UNPACK_METHODS
4053
4056
  if (unlikely(PyMethod_Check(__pyx_t_10))) {
4054
4057
  __pyx_t_20 = PyMethod_GET_SELF(__pyx_t_10);
@@ -4057,13 +4060,13 @@ static CYTHON_INLINE PyObject *__pyx_f_7pyogrio_4_err_exc_check(void) {
4057
4060
  __Pyx_INCREF(__pyx_t_20);
4058
4061
  __Pyx_INCREF(function);
4059
4062
  __Pyx_DECREF_SET(__pyx_t_10, function);
4060
- __pyx_t_12 = 1;
4063
+ __pyx_t_21 = 1;
4061
4064
  }
4062
4065
  }
4063
4066
  #endif
4064
4067
  {
4065
4068
  PyObject *__pyx_callargs[3] = {__pyx_t_20, __pyx_t_6, __pyx_t_11};
4066
- __pyx_t_7 = __Pyx_PyObject_FastCall(__pyx_t_10, __pyx_callargs+1-__pyx_t_12, 2+__pyx_t_12);
4069
+ __pyx_t_7 = __Pyx_PyObject_FastCall(__pyx_t_10, __pyx_callargs+1-__pyx_t_21, 2+__pyx_t_21);
4067
4070
  __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0;
4068
4071
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
4069
4072
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
@@ -4076,7 +4079,7 @@ static CYTHON_INLINE PyObject *__pyx_f_7pyogrio_4_err_exc_check(void) {
4076
4079
  __pyx_t_11 = __Pyx_PyInt_From_int(__pyx_v_err_no); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 167, __pyx_L1_error)
4077
4080
  __Pyx_GOTREF(__pyx_t_11);
4078
4081
  __pyx_t_6 = NULL;
4079
- __pyx_t_12 = 0;
4082
+ __pyx_t_21 = 0;
4080
4083
  #if CYTHON_UNPACK_METHODS
4081
4084
  if (unlikely(PyMethod_Check(__pyx_t_7))) {
4082
4085
  __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_7);
@@ -4085,13 +4088,13 @@ static CYTHON_INLINE PyObject *__pyx_f_7pyogrio_4_err_exc_check(void) {
4085
4088
  __Pyx_INCREF(__pyx_t_6);
4086
4089
  __Pyx_INCREF(function);
4087
4090
  __Pyx_DECREF_SET(__pyx_t_7, function);
4088
- __pyx_t_12 = 1;
4091
+ __pyx_t_21 = 1;
4089
4092
  }
4090
4093
  }
4091
4094
  #endif
4092
4095
  {
4093
4096
  PyObject *__pyx_callargs[4] = {__pyx_t_6, __pyx_t_10, __pyx_t_11, __pyx_v_msg};
4094
- __pyx_t_9 = __Pyx_PyObject_FastCall(__pyx_t_7, __pyx_callargs+1-__pyx_t_12, 3+__pyx_t_12);
4097
+ __pyx_t_9 = __Pyx_PyObject_FastCall(__pyx_t_7, __pyx_callargs+1-__pyx_t_21, 3+__pyx_t_21);
4095
4098
  __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
4096
4099
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
4097
4100
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
@@ -4148,7 +4151,7 @@ static CYTHON_INLINE PyObject *__pyx_f_7pyogrio_4_err_exc_check(void) {
4148
4151
  __pyx_t_11 = 0;
4149
4152
  __pyx_t_10 = 0;
4150
4153
  __pyx_t_10 = NULL;
4151
- __pyx_t_12 = 0;
4154
+ __pyx_t_21 = 0;
4152
4155
  #if CYTHON_UNPACK_METHODS
4153
4156
  if (likely(PyMethod_Check(__pyx_t_7))) {
4154
4157
  __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_7);
@@ -4157,13 +4160,13 @@ static CYTHON_INLINE PyObject *__pyx_f_7pyogrio_4_err_exc_check(void) {
4157
4160
  __Pyx_INCREF(__pyx_t_10);
4158
4161
  __Pyx_INCREF(function);
4159
4162
  __Pyx_DECREF_SET(__pyx_t_7, function);
4160
- __pyx_t_12 = 1;
4163
+ __pyx_t_21 = 1;
4161
4164
  }
4162
4165
  }
4163
4166
  #endif
4164
4167
  {
4165
4168
  PyObject *__pyx_callargs[2] = {__pyx_t_10, __pyx_t_6};
4166
- __pyx_t_9 = __Pyx_PyObject_FastCall(__pyx_t_7, __pyx_callargs+1-__pyx_t_12, 1+__pyx_t_12);
4169
+ __pyx_t_9 = __Pyx_PyObject_FastCall(__pyx_t_7, __pyx_callargs+1-__pyx_t_21, 1+__pyx_t_21);
4167
4170
  __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
4168
4171
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
4169
4172
  if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 170, __pyx_L1_error)
@@ -4498,7 +4501,7 @@ static int __pyx_f_7pyogrio_4_err_exc_wrap_ogrerr(int __pyx_v_err) {
4498
4501
  PyObject *__pyx_t_4 = NULL;
4499
4502
  PyObject *__pyx_t_5 = NULL;
4500
4503
  PyObject *__pyx_t_6 = NULL;
4501
- int __pyx_t_7;
4504
+ unsigned int __pyx_t_7;
4502
4505
  int __pyx_lineno = 0;
4503
4506
  const char *__pyx_filename = NULL;
4504
4507
  int __pyx_clineno = 0;
@@ -4615,7 +4618,7 @@ static void __pyx_f_7pyogrio_4_err_error_handler(CPLErr __pyx_v_err_class, int _
4615
4618
  PyObject *__pyx_t_2 = NULL;
4616
4619
  PyObject *__pyx_t_3 = NULL;
4617
4620
  PyObject *__pyx_t_4 = NULL;
4618
- int __pyx_t_5;
4621
+ unsigned int __pyx_t_5;
4619
4622
  int __pyx_lineno = 0;
4620
4623
  const char *__pyx_filename = NULL;
4621
4624
  int __pyx_clineno = 0;
@@ -9848,6 +9851,9 @@ static PyTypeObject __pyx_CyFunctionType_type = {
9848
9851
  #if PY_VERSION_HEX >= 0x030C0000
9849
9852
  0,
9850
9853
  #endif
9854
+ #if PY_VERSION_HEX >= 0x030d00A4
9855
+ 0,
9856
+ #endif
9851
9857
  #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000
9852
9858
  0,
9853
9859
  #endif
@@ -10252,12 +10258,19 @@ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_CPLErr(CPLErr value) {
10252
10258
  }
10253
10259
  }
10254
10260
  {
10255
- int one = 1; int little = (int)*(unsigned char *)&one;
10256
10261
  unsigned char *bytes = (unsigned char *)&value;
10257
- #if !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030d0000
10262
+ #if !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX >= 0x030d00A4
10263
+ if (is_unsigned) {
10264
+ return PyLong_FromUnsignedNativeBytes(bytes, sizeof(value), -1);
10265
+ } else {
10266
+ return PyLong_FromNativeBytes(bytes, sizeof(value), -1);
10267
+ }
10268
+ #elif !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030d0000
10269
+ int one = 1; int little = (int)*(unsigned char *)&one;
10258
10270
  return _PyLong_FromByteArray(bytes, sizeof(CPLErr),
10259
10271
  little, !is_unsigned);
10260
10272
  #else
10273
+ int one = 1; int little = (int)*(unsigned char *)&one;
10261
10274
  PyObject *from_bytes, *result = NULL;
10262
10275
  PyObject *py_bytes = NULL, *arg_tuple = NULL, *kwds = NULL, *order_str = NULL;
10263
10276
  from_bytes = PyObject_GetAttrString((PyObject*)&PyLong_Type, "from_bytes");
@@ -10316,12 +10329,19 @@ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) {
10316
10329
  }
10317
10330
  }
10318
10331
  {
10319
- int one = 1; int little = (int)*(unsigned char *)&one;
10320
10332
  unsigned char *bytes = (unsigned char *)&value;
10321
- #if !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030d0000
10333
+ #if !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX >= 0x030d00A4
10334
+ if (is_unsigned) {
10335
+ return PyLong_FromUnsignedNativeBytes(bytes, sizeof(value), -1);
10336
+ } else {
10337
+ return PyLong_FromNativeBytes(bytes, sizeof(value), -1);
10338
+ }
10339
+ #elif !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030d0000
10340
+ int one = 1; int little = (int)*(unsigned char *)&one;
10322
10341
  return _PyLong_FromByteArray(bytes, sizeof(int),
10323
10342
  little, !is_unsigned);
10324
10343
  #else
10344
+ int one = 1; int little = (int)*(unsigned char *)&one;
10325
10345
  PyObject *from_bytes, *result = NULL;
10326
10346
  PyObject *py_bytes = NULL, *arg_tuple = NULL, *kwds = NULL, *order_str = NULL;
10327
10347
  from_bytes = PyObject_GetAttrString((PyObject*)&PyLong_Type, "from_bytes");
@@ -10396,12 +10416,19 @@ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
10396
10416
  }
10397
10417
  }
10398
10418
  {
10399
- int one = 1; int little = (int)*(unsigned char *)&one;
10400
10419
  unsigned char *bytes = (unsigned char *)&value;
10401
- #if !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030d0000
10420
+ #if !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX >= 0x030d00A4
10421
+ if (is_unsigned) {
10422
+ return PyLong_FromUnsignedNativeBytes(bytes, sizeof(value), -1);
10423
+ } else {
10424
+ return PyLong_FromNativeBytes(bytes, sizeof(value), -1);
10425
+ }
10426
+ #elif !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030d0000
10427
+ int one = 1; int little = (int)*(unsigned char *)&one;
10402
10428
  return _PyLong_FromByteArray(bytes, sizeof(long),
10403
10429
  little, !is_unsigned);
10404
10430
  #else
10431
+ int one = 1; int little = (int)*(unsigned char *)&one;
10405
10432
  PyObject *from_bytes, *result = NULL;
10406
10433
  PyObject *py_bytes = NULL, *arg_tuple = NULL, *kwds = NULL, *order_str = NULL;
10407
10434
  from_bytes = PyObject_GetAttrString((PyObject*)&PyLong_Type, "from_bytes");
@@ -10473,245 +10500,239 @@ static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
10473
10500
  }
10474
10501
  return (long) val;
10475
10502
  }
10476
- } else
10503
+ }
10477
10504
  #endif
10478
- if (likely(PyLong_Check(x))) {
10479
- if (is_unsigned) {
10505
+ if (unlikely(!PyLong_Check(x))) {
10506
+ long val;
10507
+ PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
10508
+ if (!tmp) return (long) -1;
10509
+ val = __Pyx_PyInt_As_long(tmp);
10510
+ Py_DECREF(tmp);
10511
+ return val;
10512
+ }
10513
+ if (is_unsigned) {
10480
10514
  #if CYTHON_USE_PYLONG_INTERNALS
10481
- if (unlikely(__Pyx_PyLong_IsNeg(x))) {
10482
- goto raise_neg_overflow;
10483
- } else if (__Pyx_PyLong_IsCompact(x)) {
10484
- __PYX_VERIFY_RETURN_INT(long, __Pyx_compact_upylong, __Pyx_PyLong_CompactValueUnsigned(x))
10485
- } else {
10486
- const digit* digits = __Pyx_PyLong_Digits(x);
10487
- assert(__Pyx_PyLong_DigitCount(x) > 1);
10488
- switch (__Pyx_PyLong_DigitCount(x)) {
10489
- case 2:
10490
- if ((8 * sizeof(long) > 1 * PyLong_SHIFT)) {
10491
- if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
10492
- __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
10493
- } else if ((8 * sizeof(long) >= 2 * PyLong_SHIFT)) {
10494
- return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
10495
- }
10515
+ if (unlikely(__Pyx_PyLong_IsNeg(x))) {
10516
+ goto raise_neg_overflow;
10517
+ } else if (__Pyx_PyLong_IsCompact(x)) {
10518
+ __PYX_VERIFY_RETURN_INT(long, __Pyx_compact_upylong, __Pyx_PyLong_CompactValueUnsigned(x))
10519
+ } else {
10520
+ const digit* digits = __Pyx_PyLong_Digits(x);
10521
+ assert(__Pyx_PyLong_DigitCount(x) > 1);
10522
+ switch (__Pyx_PyLong_DigitCount(x)) {
10523
+ case 2:
10524
+ if ((8 * sizeof(long) > 1 * PyLong_SHIFT)) {
10525
+ if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
10526
+ __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
10527
+ } else if ((8 * sizeof(long) >= 2 * PyLong_SHIFT)) {
10528
+ return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
10496
10529
  }
10497
- break;
10498
- case 3:
10499
- if ((8 * sizeof(long) > 2 * PyLong_SHIFT)) {
10500
- if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
10501
- __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
10502
- } else if ((8 * sizeof(long) >= 3 * PyLong_SHIFT)) {
10503
- return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
10504
- }
10530
+ }
10531
+ break;
10532
+ case 3:
10533
+ if ((8 * sizeof(long) > 2 * PyLong_SHIFT)) {
10534
+ if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
10535
+ __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
10536
+ } else if ((8 * sizeof(long) >= 3 * PyLong_SHIFT)) {
10537
+ return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
10505
10538
  }
10506
- break;
10507
- case 4:
10508
- if ((8 * sizeof(long) > 3 * PyLong_SHIFT)) {
10509
- if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
10510
- __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])))
10511
- } else if ((8 * sizeof(long) >= 4 * PyLong_SHIFT)) {
10512
- return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
10513
- }
10539
+ }
10540
+ break;
10541
+ case 4:
10542
+ if ((8 * sizeof(long) > 3 * PyLong_SHIFT)) {
10543
+ if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
10544
+ __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])))
10545
+ } else if ((8 * sizeof(long) >= 4 * PyLong_SHIFT)) {
10546
+ return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
10514
10547
  }
10515
- break;
10516
- }
10548
+ }
10549
+ break;
10517
10550
  }
10551
+ }
10518
10552
  #endif
10519
10553
  #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A7
10520
- if (unlikely(Py_SIZE(x) < 0)) {
10521
- goto raise_neg_overflow;
10522
- }
10554
+ if (unlikely(Py_SIZE(x) < 0)) {
10555
+ goto raise_neg_overflow;
10556
+ }
10523
10557
  #else
10524
- {
10525
- int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
10526
- if (unlikely(result < 0))
10527
- return (long) -1;
10528
- if (unlikely(result == 1))
10529
- goto raise_neg_overflow;
10530
- }
10558
+ {
10559
+ int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
10560
+ if (unlikely(result < 0))
10561
+ return (long) -1;
10562
+ if (unlikely(result == 1))
10563
+ goto raise_neg_overflow;
10564
+ }
10531
10565
  #endif
10532
- if ((sizeof(long) <= sizeof(unsigned long))) {
10533
- __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x))
10566
+ if ((sizeof(long) <= sizeof(unsigned long))) {
10567
+ __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x))
10534
10568
  #ifdef HAVE_LONG_LONG
10535
- } else if ((sizeof(long) <= sizeof(unsigned PY_LONG_LONG))) {
10536
- __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
10569
+ } else if ((sizeof(long) <= sizeof(unsigned PY_LONG_LONG))) {
10570
+ __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
10537
10571
  #endif
10538
- }
10539
- } else {
10572
+ }
10573
+ } else {
10540
10574
  #if CYTHON_USE_PYLONG_INTERNALS
10541
- if (__Pyx_PyLong_IsCompact(x)) {
10542
- __PYX_VERIFY_RETURN_INT(long, __Pyx_compact_pylong, __Pyx_PyLong_CompactValue(x))
10543
- } else {
10544
- const digit* digits = __Pyx_PyLong_Digits(x);
10545
- assert(__Pyx_PyLong_DigitCount(x) > 1);
10546
- switch (__Pyx_PyLong_SignedDigitCount(x)) {
10547
- case -2:
10548
- if ((8 * sizeof(long) - 1 > 1 * PyLong_SHIFT)) {
10549
- if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
10550
- __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
10551
- } else if ((8 * sizeof(long) - 1 > 2 * PyLong_SHIFT)) {
10552
- return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
10553
- }
10575
+ if (__Pyx_PyLong_IsCompact(x)) {
10576
+ __PYX_VERIFY_RETURN_INT(long, __Pyx_compact_pylong, __Pyx_PyLong_CompactValue(x))
10577
+ } else {
10578
+ const digit* digits = __Pyx_PyLong_Digits(x);
10579
+ assert(__Pyx_PyLong_DigitCount(x) > 1);
10580
+ switch (__Pyx_PyLong_SignedDigitCount(x)) {
10581
+ case -2:
10582
+ if ((8 * sizeof(long) - 1 > 1 * PyLong_SHIFT)) {
10583
+ if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
10584
+ __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
10585
+ } else if ((8 * sizeof(long) - 1 > 2 * PyLong_SHIFT)) {
10586
+ return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
10554
10587
  }
10555
- break;
10556
- case 2:
10557
- if ((8 * sizeof(long) > 1 * PyLong_SHIFT)) {
10558
- if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
10559
- __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
10560
- } else if ((8 * sizeof(long) - 1 > 2 * PyLong_SHIFT)) {
10561
- return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
10562
- }
10588
+ }
10589
+ break;
10590
+ case 2:
10591
+ if ((8 * sizeof(long) > 1 * PyLong_SHIFT)) {
10592
+ if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
10593
+ __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
10594
+ } else if ((8 * sizeof(long) - 1 > 2 * PyLong_SHIFT)) {
10595
+ return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
10563
10596
  }
10564
- break;
10565
- case -3:
10566
- if ((8 * sizeof(long) - 1 > 2 * PyLong_SHIFT)) {
10567
- if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
10568
- __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
10569
- } else if ((8 * sizeof(long) - 1 > 3 * PyLong_SHIFT)) {
10570
- return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
10571
- }
10597
+ }
10598
+ break;
10599
+ case -3:
10600
+ if ((8 * sizeof(long) - 1 > 2 * PyLong_SHIFT)) {
10601
+ if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
10602
+ __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
10603
+ } else if ((8 * sizeof(long) - 1 > 3 * PyLong_SHIFT)) {
10604
+ return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
10572
10605
  }
10573
- break;
10574
- case 3:
10575
- if ((8 * sizeof(long) > 2 * PyLong_SHIFT)) {
10576
- if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
10577
- __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
10578
- } else if ((8 * sizeof(long) - 1 > 3 * PyLong_SHIFT)) {
10579
- return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
10580
- }
10606
+ }
10607
+ break;
10608
+ case 3:
10609
+ if ((8 * sizeof(long) > 2 * PyLong_SHIFT)) {
10610
+ if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
10611
+ __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
10612
+ } else if ((8 * sizeof(long) - 1 > 3 * PyLong_SHIFT)) {
10613
+ return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
10581
10614
  }
10582
- break;
10583
- case -4:
10584
- if ((8 * sizeof(long) - 1 > 3 * PyLong_SHIFT)) {
10585
- if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
10586
- __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])))
10587
- } else if ((8 * sizeof(long) - 1 > 4 * PyLong_SHIFT)) {
10588
- return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
10589
- }
10615
+ }
10616
+ break;
10617
+ case -4:
10618
+ if ((8 * sizeof(long) - 1 > 3 * PyLong_SHIFT)) {
10619
+ if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
10620
+ __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])))
10621
+ } else if ((8 * sizeof(long) - 1 > 4 * PyLong_SHIFT)) {
10622
+ return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
10590
10623
  }
10591
- break;
10592
- case 4:
10593
- if ((8 * sizeof(long) > 3 * PyLong_SHIFT)) {
10594
- if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
10595
- __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])))
10596
- } else if ((8 * sizeof(long) - 1 > 4 * PyLong_SHIFT)) {
10597
- return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
10598
- }
10624
+ }
10625
+ break;
10626
+ case 4:
10627
+ if ((8 * sizeof(long) > 3 * PyLong_SHIFT)) {
10628
+ if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
10629
+ __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])))
10630
+ } else if ((8 * sizeof(long) - 1 > 4 * PyLong_SHIFT)) {
10631
+ return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
10599
10632
  }
10600
- break;
10601
- }
10633
+ }
10634
+ break;
10602
10635
  }
10636
+ }
10603
10637
  #endif
10604
- if ((sizeof(long) <= sizeof(long))) {
10605
- __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x))
10638
+ if ((sizeof(long) <= sizeof(long))) {
10639
+ __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x))
10606
10640
  #ifdef HAVE_LONG_LONG
10607
- } else if ((sizeof(long) <= sizeof(PY_LONG_LONG))) {
10608
- __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x))
10641
+ } else if ((sizeof(long) <= sizeof(PY_LONG_LONG))) {
10642
+ __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x))
10609
10643
  #endif
10610
- }
10644
+ }
10645
+ }
10646
+ {
10647
+ long val;
10648
+ int ret = -1;
10649
+ #if PY_VERSION_HEX >= 0x030d00A6 && !CYTHON_COMPILING_IN_LIMITED_API
10650
+ Py_ssize_t bytes_copied = PyLong_AsNativeBytes(
10651
+ x, &val, sizeof(val), Py_ASNATIVEBYTES_NATIVE_ENDIAN | (is_unsigned ? Py_ASNATIVEBYTES_UNSIGNED_BUFFER | Py_ASNATIVEBYTES_REJECT_NEGATIVE : 0));
10652
+ if (unlikely(bytes_copied == -1)) {
10653
+ } else if (unlikely(bytes_copied > (Py_ssize_t) sizeof(val))) {
10654
+ goto raise_overflow;
10655
+ } else {
10656
+ ret = 0;
10657
+ }
10658
+ #elif PY_VERSION_HEX < 0x030d0000 && !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API) || defined(_PyLong_AsByteArray)
10659
+ int one = 1; int is_little = (int)*(unsigned char *)&one;
10660
+ unsigned char *bytes = (unsigned char *)&val;
10661
+ ret = _PyLong_AsByteArray((PyLongObject *)x,
10662
+ bytes, sizeof(val),
10663
+ is_little, !is_unsigned);
10664
+ #else
10665
+ PyObject *v;
10666
+ PyObject *stepval = NULL, *mask = NULL, *shift = NULL;
10667
+ int bits, remaining_bits, is_negative = 0;
10668
+ int chunk_size = (sizeof(long) < 8) ? 30 : 62;
10669
+ if (likely(PyLong_CheckExact(x))) {
10670
+ v = __Pyx_NewRef(x);
10671
+ } else {
10672
+ v = PyNumber_Long(x);
10673
+ if (unlikely(!v)) return (long) -1;
10674
+ assert(PyLong_CheckExact(v));
10611
10675
  }
10612
10676
  {
10613
- long val;
10614
- PyObject *v = __Pyx_PyNumber_IntOrLong(x);
10615
- #if PY_MAJOR_VERSION < 3
10616
- if (likely(v) && !PyLong_Check(v)) {
10617
- PyObject *tmp = v;
10618
- v = PyNumber_Long(tmp);
10619
- Py_DECREF(tmp);
10620
- }
10621
- #endif
10622
- if (likely(v)) {
10623
- int ret = -1;
10624
- #if PY_VERSION_HEX < 0x030d0000 && !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API) || defined(_PyLong_AsByteArray)
10625
- int one = 1; int is_little = (int)*(unsigned char *)&one;
10626
- unsigned char *bytes = (unsigned char *)&val;
10627
- ret = _PyLong_AsByteArray((PyLongObject *)v,
10628
- bytes, sizeof(val),
10629
- is_little, !is_unsigned);
10630
- #else
10631
- PyObject *stepval = NULL, *mask = NULL, *shift = NULL;
10632
- int bits, remaining_bits, is_negative = 0;
10633
- long idigit;
10634
- int chunk_size = (sizeof(long) < 8) ? 30 : 62;
10635
- if (unlikely(!PyLong_CheckExact(v))) {
10636
- PyObject *tmp = v;
10637
- v = PyNumber_Long(v);
10638
- assert(PyLong_CheckExact(v));
10639
- Py_DECREF(tmp);
10640
- if (unlikely(!v)) return (long) -1;
10641
- }
10642
- #if CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030B0000
10643
- if (Py_SIZE(x) == 0)
10644
- return (long) 0;
10645
- is_negative = Py_SIZE(x) < 0;
10646
- #else
10647
- {
10648
- int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
10649
- if (unlikely(result < 0))
10650
- return (long) -1;
10651
- is_negative = result == 1;
10652
- }
10653
- #endif
10654
- if (is_unsigned && unlikely(is_negative)) {
10655
- goto raise_neg_overflow;
10656
- } else if (is_negative) {
10657
- stepval = PyNumber_Invert(v);
10658
- if (unlikely(!stepval))
10659
- return (long) -1;
10660
- } else {
10661
- stepval = __Pyx_NewRef(v);
10662
- }
10663
- val = (long) 0;
10664
- mask = PyLong_FromLong((1L << chunk_size) - 1); if (unlikely(!mask)) goto done;
10665
- shift = PyLong_FromLong(chunk_size); if (unlikely(!shift)) goto done;
10666
- for (bits = 0; bits < (int) sizeof(long) * 8 - chunk_size; bits += chunk_size) {
10667
- PyObject *tmp, *digit;
10668
- digit = PyNumber_And(stepval, mask);
10669
- if (unlikely(!digit)) goto done;
10670
- idigit = PyLong_AsLong(digit);
10671
- Py_DECREF(digit);
10672
- if (unlikely(idigit < 0)) goto done;
10673
- tmp = PyNumber_Rshift(stepval, shift);
10674
- if (unlikely(!tmp)) goto done;
10675
- Py_DECREF(stepval); stepval = tmp;
10676
- val |= ((long) idigit) << bits;
10677
- #if CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030B0000
10678
- if (Py_SIZE(stepval) == 0)
10679
- goto unpacking_done;
10680
- #endif
10681
- }
10682
- idigit = PyLong_AsLong(stepval);
10683
- if (unlikely(idigit < 0)) goto done;
10684
- remaining_bits = ((int) sizeof(long) * 8) - bits - (is_unsigned ? 0 : 1);
10685
- if (unlikely(idigit >= (1L << remaining_bits)))
10686
- goto raise_overflow;
10687
- val |= ((long) idigit) << bits;
10688
- #if CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030B0000
10689
- unpacking_done:
10690
- #endif
10691
- if (!is_unsigned) {
10692
- if (unlikely(val & (((long) 1) << (sizeof(long) * 8 - 1))))
10693
- goto raise_overflow;
10694
- if (is_negative)
10695
- val = ~val;
10696
- }
10697
- ret = 0;
10698
- done:
10699
- Py_XDECREF(shift);
10700
- Py_XDECREF(mask);
10701
- Py_XDECREF(stepval);
10702
- #endif
10677
+ int result = PyObject_RichCompareBool(v, Py_False, Py_LT);
10678
+ if (unlikely(result < 0)) {
10703
10679
  Py_DECREF(v);
10704
- if (likely(!ret))
10705
- return val;
10680
+ return (long) -1;
10706
10681
  }
10707
- return (long) -1;
10682
+ is_negative = result == 1;
10708
10683
  }
10709
- } else {
10710
- long val;
10711
- PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
10712
- if (!tmp) return (long) -1;
10713
- val = __Pyx_PyInt_As_long(tmp);
10714
- Py_DECREF(tmp);
10684
+ if (is_unsigned && unlikely(is_negative)) {
10685
+ Py_DECREF(v);
10686
+ goto raise_neg_overflow;
10687
+ } else if (is_negative) {
10688
+ stepval = PyNumber_Invert(v);
10689
+ Py_DECREF(v);
10690
+ if (unlikely(!stepval))
10691
+ return (long) -1;
10692
+ } else {
10693
+ stepval = v;
10694
+ }
10695
+ v = NULL;
10696
+ val = (long) 0;
10697
+ mask = PyLong_FromLong((1L << chunk_size) - 1); if (unlikely(!mask)) goto done;
10698
+ shift = PyLong_FromLong(chunk_size); if (unlikely(!shift)) goto done;
10699
+ for (bits = 0; bits < (int) sizeof(long) * 8 - chunk_size; bits += chunk_size) {
10700
+ PyObject *tmp, *digit;
10701
+ long idigit;
10702
+ digit = PyNumber_And(stepval, mask);
10703
+ if (unlikely(!digit)) goto done;
10704
+ idigit = PyLong_AsLong(digit);
10705
+ Py_DECREF(digit);
10706
+ if (unlikely(idigit < 0)) goto done;
10707
+ val |= ((long) idigit) << bits;
10708
+ tmp = PyNumber_Rshift(stepval, shift);
10709
+ if (unlikely(!tmp)) goto done;
10710
+ Py_DECREF(stepval); stepval = tmp;
10711
+ }
10712
+ Py_DECREF(shift); shift = NULL;
10713
+ Py_DECREF(mask); mask = NULL;
10714
+ {
10715
+ long idigit = PyLong_AsLong(stepval);
10716
+ if (unlikely(idigit < 0)) goto done;
10717
+ remaining_bits = ((int) sizeof(long) * 8) - bits - (is_unsigned ? 0 : 1);
10718
+ if (unlikely(idigit >= (1L << remaining_bits)))
10719
+ goto raise_overflow;
10720
+ val |= ((long) idigit) << bits;
10721
+ }
10722
+ if (!is_unsigned) {
10723
+ if (unlikely(val & (((long) 1) << (sizeof(long) * 8 - 1))))
10724
+ goto raise_overflow;
10725
+ if (is_negative)
10726
+ val = ~val;
10727
+ }
10728
+ ret = 0;
10729
+ done:
10730
+ Py_XDECREF(shift);
10731
+ Py_XDECREF(mask);
10732
+ Py_XDECREF(stepval);
10733
+ #endif
10734
+ if (unlikely(ret))
10735
+ return (long) -1;
10715
10736
  return val;
10716
10737
  }
10717
10738
  raise_overflow:
@@ -10746,245 +10767,239 @@ static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
10746
10767
  }
10747
10768
  return (int) val;
10748
10769
  }
10749
- } else
10770
+ }
10750
10771
  #endif
10751
- if (likely(PyLong_Check(x))) {
10752
- if (is_unsigned) {
10772
+ if (unlikely(!PyLong_Check(x))) {
10773
+ int val;
10774
+ PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
10775
+ if (!tmp) return (int) -1;
10776
+ val = __Pyx_PyInt_As_int(tmp);
10777
+ Py_DECREF(tmp);
10778
+ return val;
10779
+ }
10780
+ if (is_unsigned) {
10753
10781
  #if CYTHON_USE_PYLONG_INTERNALS
10754
- if (unlikely(__Pyx_PyLong_IsNeg(x))) {
10755
- goto raise_neg_overflow;
10756
- } else if (__Pyx_PyLong_IsCompact(x)) {
10757
- __PYX_VERIFY_RETURN_INT(int, __Pyx_compact_upylong, __Pyx_PyLong_CompactValueUnsigned(x))
10758
- } else {
10759
- const digit* digits = __Pyx_PyLong_Digits(x);
10760
- assert(__Pyx_PyLong_DigitCount(x) > 1);
10761
- switch (__Pyx_PyLong_DigitCount(x)) {
10762
- case 2:
10763
- if ((8 * sizeof(int) > 1 * PyLong_SHIFT)) {
10764
- if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
10765
- __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
10766
- } else if ((8 * sizeof(int) >= 2 * PyLong_SHIFT)) {
10767
- return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
10768
- }
10782
+ if (unlikely(__Pyx_PyLong_IsNeg(x))) {
10783
+ goto raise_neg_overflow;
10784
+ } else if (__Pyx_PyLong_IsCompact(x)) {
10785
+ __PYX_VERIFY_RETURN_INT(int, __Pyx_compact_upylong, __Pyx_PyLong_CompactValueUnsigned(x))
10786
+ } else {
10787
+ const digit* digits = __Pyx_PyLong_Digits(x);
10788
+ assert(__Pyx_PyLong_DigitCount(x) > 1);
10789
+ switch (__Pyx_PyLong_DigitCount(x)) {
10790
+ case 2:
10791
+ if ((8 * sizeof(int) > 1 * PyLong_SHIFT)) {
10792
+ if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
10793
+ __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
10794
+ } else if ((8 * sizeof(int) >= 2 * PyLong_SHIFT)) {
10795
+ return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
10769
10796
  }
10770
- break;
10771
- case 3:
10772
- if ((8 * sizeof(int) > 2 * PyLong_SHIFT)) {
10773
- if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
10774
- __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
10775
- } else if ((8 * sizeof(int) >= 3 * PyLong_SHIFT)) {
10776
- return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
10777
- }
10797
+ }
10798
+ break;
10799
+ case 3:
10800
+ if ((8 * sizeof(int) > 2 * PyLong_SHIFT)) {
10801
+ if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
10802
+ __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
10803
+ } else if ((8 * sizeof(int) >= 3 * PyLong_SHIFT)) {
10804
+ return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
10778
10805
  }
10779
- break;
10780
- case 4:
10781
- if ((8 * sizeof(int) > 3 * PyLong_SHIFT)) {
10782
- if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
10783
- __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])))
10784
- } else if ((8 * sizeof(int) >= 4 * PyLong_SHIFT)) {
10785
- return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
10786
- }
10806
+ }
10807
+ break;
10808
+ case 4:
10809
+ if ((8 * sizeof(int) > 3 * PyLong_SHIFT)) {
10810
+ if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
10811
+ __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])))
10812
+ } else if ((8 * sizeof(int) >= 4 * PyLong_SHIFT)) {
10813
+ return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
10787
10814
  }
10788
- break;
10789
- }
10815
+ }
10816
+ break;
10790
10817
  }
10818
+ }
10791
10819
  #endif
10792
10820
  #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A7
10793
- if (unlikely(Py_SIZE(x) < 0)) {
10794
- goto raise_neg_overflow;
10795
- }
10821
+ if (unlikely(Py_SIZE(x) < 0)) {
10822
+ goto raise_neg_overflow;
10823
+ }
10796
10824
  #else
10797
- {
10798
- int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
10799
- if (unlikely(result < 0))
10800
- return (int) -1;
10801
- if (unlikely(result == 1))
10802
- goto raise_neg_overflow;
10803
- }
10825
+ {
10826
+ int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
10827
+ if (unlikely(result < 0))
10828
+ return (int) -1;
10829
+ if (unlikely(result == 1))
10830
+ goto raise_neg_overflow;
10831
+ }
10804
10832
  #endif
10805
- if ((sizeof(int) <= sizeof(unsigned long))) {
10806
- __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x))
10833
+ if ((sizeof(int) <= sizeof(unsigned long))) {
10834
+ __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x))
10807
10835
  #ifdef HAVE_LONG_LONG
10808
- } else if ((sizeof(int) <= sizeof(unsigned PY_LONG_LONG))) {
10809
- __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
10836
+ } else if ((sizeof(int) <= sizeof(unsigned PY_LONG_LONG))) {
10837
+ __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
10810
10838
  #endif
10811
- }
10812
- } else {
10839
+ }
10840
+ } else {
10813
10841
  #if CYTHON_USE_PYLONG_INTERNALS
10814
- if (__Pyx_PyLong_IsCompact(x)) {
10815
- __PYX_VERIFY_RETURN_INT(int, __Pyx_compact_pylong, __Pyx_PyLong_CompactValue(x))
10816
- } else {
10817
- const digit* digits = __Pyx_PyLong_Digits(x);
10818
- assert(__Pyx_PyLong_DigitCount(x) > 1);
10819
- switch (__Pyx_PyLong_SignedDigitCount(x)) {
10820
- case -2:
10821
- if ((8 * sizeof(int) - 1 > 1 * PyLong_SHIFT)) {
10822
- if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
10823
- __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
10824
- } else if ((8 * sizeof(int) - 1 > 2 * PyLong_SHIFT)) {
10825
- return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
10826
- }
10842
+ if (__Pyx_PyLong_IsCompact(x)) {
10843
+ __PYX_VERIFY_RETURN_INT(int, __Pyx_compact_pylong, __Pyx_PyLong_CompactValue(x))
10844
+ } else {
10845
+ const digit* digits = __Pyx_PyLong_Digits(x);
10846
+ assert(__Pyx_PyLong_DigitCount(x) > 1);
10847
+ switch (__Pyx_PyLong_SignedDigitCount(x)) {
10848
+ case -2:
10849
+ if ((8 * sizeof(int) - 1 > 1 * PyLong_SHIFT)) {
10850
+ if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
10851
+ __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
10852
+ } else if ((8 * sizeof(int) - 1 > 2 * PyLong_SHIFT)) {
10853
+ return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
10827
10854
  }
10828
- break;
10829
- case 2:
10830
- if ((8 * sizeof(int) > 1 * PyLong_SHIFT)) {
10831
- if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
10832
- __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
10833
- } else if ((8 * sizeof(int) - 1 > 2 * PyLong_SHIFT)) {
10834
- return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
10835
- }
10855
+ }
10856
+ break;
10857
+ case 2:
10858
+ if ((8 * sizeof(int) > 1 * PyLong_SHIFT)) {
10859
+ if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
10860
+ __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
10861
+ } else if ((8 * sizeof(int) - 1 > 2 * PyLong_SHIFT)) {
10862
+ return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
10836
10863
  }
10837
- break;
10838
- case -3:
10839
- if ((8 * sizeof(int) - 1 > 2 * PyLong_SHIFT)) {
10840
- if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
10841
- __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
10842
- } else if ((8 * sizeof(int) - 1 > 3 * PyLong_SHIFT)) {
10843
- return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
10844
- }
10864
+ }
10865
+ break;
10866
+ case -3:
10867
+ if ((8 * sizeof(int) - 1 > 2 * PyLong_SHIFT)) {
10868
+ if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
10869
+ __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
10870
+ } else if ((8 * sizeof(int) - 1 > 3 * PyLong_SHIFT)) {
10871
+ return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
10845
10872
  }
10846
- break;
10847
- case 3:
10848
- if ((8 * sizeof(int) > 2 * PyLong_SHIFT)) {
10849
- if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
10850
- __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
10851
- } else if ((8 * sizeof(int) - 1 > 3 * PyLong_SHIFT)) {
10852
- return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
10853
- }
10873
+ }
10874
+ break;
10875
+ case 3:
10876
+ if ((8 * sizeof(int) > 2 * PyLong_SHIFT)) {
10877
+ if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
10878
+ __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
10879
+ } else if ((8 * sizeof(int) - 1 > 3 * PyLong_SHIFT)) {
10880
+ return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
10854
10881
  }
10855
- break;
10856
- case -4:
10857
- if ((8 * sizeof(int) - 1 > 3 * PyLong_SHIFT)) {
10858
- if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
10859
- __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])))
10860
- } else if ((8 * sizeof(int) - 1 > 4 * PyLong_SHIFT)) {
10861
- return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
10862
- }
10882
+ }
10883
+ break;
10884
+ case -4:
10885
+ if ((8 * sizeof(int) - 1 > 3 * PyLong_SHIFT)) {
10886
+ if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
10887
+ __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])))
10888
+ } else if ((8 * sizeof(int) - 1 > 4 * PyLong_SHIFT)) {
10889
+ return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
10863
10890
  }
10864
- break;
10865
- case 4:
10866
- if ((8 * sizeof(int) > 3 * PyLong_SHIFT)) {
10867
- if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
10868
- __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])))
10869
- } else if ((8 * sizeof(int) - 1 > 4 * PyLong_SHIFT)) {
10870
- return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
10871
- }
10891
+ }
10892
+ break;
10893
+ case 4:
10894
+ if ((8 * sizeof(int) > 3 * PyLong_SHIFT)) {
10895
+ if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
10896
+ __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])))
10897
+ } else if ((8 * sizeof(int) - 1 > 4 * PyLong_SHIFT)) {
10898
+ return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
10872
10899
  }
10873
- break;
10874
- }
10900
+ }
10901
+ break;
10875
10902
  }
10903
+ }
10876
10904
  #endif
10877
- if ((sizeof(int) <= sizeof(long))) {
10878
- __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x))
10905
+ if ((sizeof(int) <= sizeof(long))) {
10906
+ __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x))
10879
10907
  #ifdef HAVE_LONG_LONG
10880
- } else if ((sizeof(int) <= sizeof(PY_LONG_LONG))) {
10881
- __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x))
10908
+ } else if ((sizeof(int) <= sizeof(PY_LONG_LONG))) {
10909
+ __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x))
10882
10910
  #endif
10883
- }
10911
+ }
10912
+ }
10913
+ {
10914
+ int val;
10915
+ int ret = -1;
10916
+ #if PY_VERSION_HEX >= 0x030d00A6 && !CYTHON_COMPILING_IN_LIMITED_API
10917
+ Py_ssize_t bytes_copied = PyLong_AsNativeBytes(
10918
+ x, &val, sizeof(val), Py_ASNATIVEBYTES_NATIVE_ENDIAN | (is_unsigned ? Py_ASNATIVEBYTES_UNSIGNED_BUFFER | Py_ASNATIVEBYTES_REJECT_NEGATIVE : 0));
10919
+ if (unlikely(bytes_copied == -1)) {
10920
+ } else if (unlikely(bytes_copied > (Py_ssize_t) sizeof(val))) {
10921
+ goto raise_overflow;
10922
+ } else {
10923
+ ret = 0;
10924
+ }
10925
+ #elif PY_VERSION_HEX < 0x030d0000 && !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API) || defined(_PyLong_AsByteArray)
10926
+ int one = 1; int is_little = (int)*(unsigned char *)&one;
10927
+ unsigned char *bytes = (unsigned char *)&val;
10928
+ ret = _PyLong_AsByteArray((PyLongObject *)x,
10929
+ bytes, sizeof(val),
10930
+ is_little, !is_unsigned);
10931
+ #else
10932
+ PyObject *v;
10933
+ PyObject *stepval = NULL, *mask = NULL, *shift = NULL;
10934
+ int bits, remaining_bits, is_negative = 0;
10935
+ int chunk_size = (sizeof(long) < 8) ? 30 : 62;
10936
+ if (likely(PyLong_CheckExact(x))) {
10937
+ v = __Pyx_NewRef(x);
10938
+ } else {
10939
+ v = PyNumber_Long(x);
10940
+ if (unlikely(!v)) return (int) -1;
10941
+ assert(PyLong_CheckExact(v));
10884
10942
  }
10885
10943
  {
10886
- int val;
10887
- PyObject *v = __Pyx_PyNumber_IntOrLong(x);
10888
- #if PY_MAJOR_VERSION < 3
10889
- if (likely(v) && !PyLong_Check(v)) {
10890
- PyObject *tmp = v;
10891
- v = PyNumber_Long(tmp);
10892
- Py_DECREF(tmp);
10893
- }
10894
- #endif
10895
- if (likely(v)) {
10896
- int ret = -1;
10897
- #if PY_VERSION_HEX < 0x030d0000 && !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API) || defined(_PyLong_AsByteArray)
10898
- int one = 1; int is_little = (int)*(unsigned char *)&one;
10899
- unsigned char *bytes = (unsigned char *)&val;
10900
- ret = _PyLong_AsByteArray((PyLongObject *)v,
10901
- bytes, sizeof(val),
10902
- is_little, !is_unsigned);
10903
- #else
10904
- PyObject *stepval = NULL, *mask = NULL, *shift = NULL;
10905
- int bits, remaining_bits, is_negative = 0;
10906
- long idigit;
10907
- int chunk_size = (sizeof(long) < 8) ? 30 : 62;
10908
- if (unlikely(!PyLong_CheckExact(v))) {
10909
- PyObject *tmp = v;
10910
- v = PyNumber_Long(v);
10911
- assert(PyLong_CheckExact(v));
10912
- Py_DECREF(tmp);
10913
- if (unlikely(!v)) return (int) -1;
10914
- }
10915
- #if CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030B0000
10916
- if (Py_SIZE(x) == 0)
10917
- return (int) 0;
10918
- is_negative = Py_SIZE(x) < 0;
10919
- #else
10920
- {
10921
- int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
10922
- if (unlikely(result < 0))
10923
- return (int) -1;
10924
- is_negative = result == 1;
10925
- }
10926
- #endif
10927
- if (is_unsigned && unlikely(is_negative)) {
10928
- goto raise_neg_overflow;
10929
- } else if (is_negative) {
10930
- stepval = PyNumber_Invert(v);
10931
- if (unlikely(!stepval))
10932
- return (int) -1;
10933
- } else {
10934
- stepval = __Pyx_NewRef(v);
10935
- }
10936
- val = (int) 0;
10937
- mask = PyLong_FromLong((1L << chunk_size) - 1); if (unlikely(!mask)) goto done;
10938
- shift = PyLong_FromLong(chunk_size); if (unlikely(!shift)) goto done;
10939
- for (bits = 0; bits < (int) sizeof(int) * 8 - chunk_size; bits += chunk_size) {
10940
- PyObject *tmp, *digit;
10941
- digit = PyNumber_And(stepval, mask);
10942
- if (unlikely(!digit)) goto done;
10943
- idigit = PyLong_AsLong(digit);
10944
- Py_DECREF(digit);
10945
- if (unlikely(idigit < 0)) goto done;
10946
- tmp = PyNumber_Rshift(stepval, shift);
10947
- if (unlikely(!tmp)) goto done;
10948
- Py_DECREF(stepval); stepval = tmp;
10949
- val |= ((int) idigit) << bits;
10950
- #if CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030B0000
10951
- if (Py_SIZE(stepval) == 0)
10952
- goto unpacking_done;
10953
- #endif
10954
- }
10955
- idigit = PyLong_AsLong(stepval);
10956
- if (unlikely(idigit < 0)) goto done;
10957
- remaining_bits = ((int) sizeof(int) * 8) - bits - (is_unsigned ? 0 : 1);
10958
- if (unlikely(idigit >= (1L << remaining_bits)))
10959
- goto raise_overflow;
10960
- val |= ((int) idigit) << bits;
10961
- #if CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030B0000
10962
- unpacking_done:
10963
- #endif
10964
- if (!is_unsigned) {
10965
- if (unlikely(val & (((int) 1) << (sizeof(int) * 8 - 1))))
10966
- goto raise_overflow;
10967
- if (is_negative)
10968
- val = ~val;
10969
- }
10970
- ret = 0;
10971
- done:
10972
- Py_XDECREF(shift);
10973
- Py_XDECREF(mask);
10974
- Py_XDECREF(stepval);
10975
- #endif
10944
+ int result = PyObject_RichCompareBool(v, Py_False, Py_LT);
10945
+ if (unlikely(result < 0)) {
10976
10946
  Py_DECREF(v);
10977
- if (likely(!ret))
10978
- return val;
10947
+ return (int) -1;
10979
10948
  }
10980
- return (int) -1;
10949
+ is_negative = result == 1;
10981
10950
  }
10982
- } else {
10983
- int val;
10984
- PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
10985
- if (!tmp) return (int) -1;
10986
- val = __Pyx_PyInt_As_int(tmp);
10987
- Py_DECREF(tmp);
10951
+ if (is_unsigned && unlikely(is_negative)) {
10952
+ Py_DECREF(v);
10953
+ goto raise_neg_overflow;
10954
+ } else if (is_negative) {
10955
+ stepval = PyNumber_Invert(v);
10956
+ Py_DECREF(v);
10957
+ if (unlikely(!stepval))
10958
+ return (int) -1;
10959
+ } else {
10960
+ stepval = v;
10961
+ }
10962
+ v = NULL;
10963
+ val = (int) 0;
10964
+ mask = PyLong_FromLong((1L << chunk_size) - 1); if (unlikely(!mask)) goto done;
10965
+ shift = PyLong_FromLong(chunk_size); if (unlikely(!shift)) goto done;
10966
+ for (bits = 0; bits < (int) sizeof(int) * 8 - chunk_size; bits += chunk_size) {
10967
+ PyObject *tmp, *digit;
10968
+ long idigit;
10969
+ digit = PyNumber_And(stepval, mask);
10970
+ if (unlikely(!digit)) goto done;
10971
+ idigit = PyLong_AsLong(digit);
10972
+ Py_DECREF(digit);
10973
+ if (unlikely(idigit < 0)) goto done;
10974
+ val |= ((int) idigit) << bits;
10975
+ tmp = PyNumber_Rshift(stepval, shift);
10976
+ if (unlikely(!tmp)) goto done;
10977
+ Py_DECREF(stepval); stepval = tmp;
10978
+ }
10979
+ Py_DECREF(shift); shift = NULL;
10980
+ Py_DECREF(mask); mask = NULL;
10981
+ {
10982
+ long idigit = PyLong_AsLong(stepval);
10983
+ if (unlikely(idigit < 0)) goto done;
10984
+ remaining_bits = ((int) sizeof(int) * 8) - bits - (is_unsigned ? 0 : 1);
10985
+ if (unlikely(idigit >= (1L << remaining_bits)))
10986
+ goto raise_overflow;
10987
+ val |= ((int) idigit) << bits;
10988
+ }
10989
+ if (!is_unsigned) {
10990
+ if (unlikely(val & (((int) 1) << (sizeof(int) * 8 - 1))))
10991
+ goto raise_overflow;
10992
+ if (is_negative)
10993
+ val = ~val;
10994
+ }
10995
+ ret = 0;
10996
+ done:
10997
+ Py_XDECREF(shift);
10998
+ Py_XDECREF(mask);
10999
+ Py_XDECREF(stepval);
11000
+ #endif
11001
+ if (unlikely(ret))
11002
+ return (int) -1;
10988
11003
  return val;
10989
11004
  }
10990
11005
  raise_overflow: