Skip to content

Commit 2c394fb

Browse files
Replace _PyLong_AsInt() with PyLong_AsInt() for Python 3.13+
The new public function `PyLong_AsInt()` has been introduced as part of python/cpython#108444, which renames the internal `_PyLong_AsInt()` to `PyLong_AsInt()`. This change updates the code to use the new public API while maintaining compatibility with Python versions earlier than 3.13. Fixes Rogdham#13 Signed-off-by: Mikel Olasagasti Uranga <[email protected]>
1 parent 90f783e commit 2c394fb

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

src/bin_ext/file.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ ZstdFileWriter_flush(ZstdFileWriter *self, PyObject *arg)
658658
STATE_FROM_OBJ(self);
659659

660660
/* Mode argument */
661-
mode = _PyLong_AsInt(arg);
661+
mode = PyLong_AsInt(arg);
662662

663663
assert(ZSTD_e_flush == 1 && ZSTD_e_end == 2);
664664
if (mode != ZSTD_e_flush && mode != ZSTD_e_end) {

src/bin_ext/macro_functions.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ PYZSTD_FUN_PREFIX(set_c_parameters)(PYZSTD_C_CLASS *self, PyObject *level_or_opt
1414

1515
/* Integer compression level */
1616
if (PyLong_Check(level_or_option)) {
17-
const int level = _PyLong_AsInt(level_or_option);
17+
const int level = PyLong_AsInt(level_or_option);
1818
if (level == -1 && PyErr_Occurred()) {
1919
PyErr_SetString(PyExc_ValueError,
2020
"Compression level should be 32-bit signed int value.");
@@ -52,14 +52,14 @@ PYZSTD_FUN_PREFIX(set_c_parameters)(PYZSTD_C_CLASS *self, PyObject *level_or_opt
5252
}
5353

5454
/* Both key & value should be 32-bit signed int */
55-
const int key_v = _PyLong_AsInt(key);
55+
const int key_v = PyLong_AsInt(key);
5656
if (key_v == -1 && PyErr_Occurred()) {
5757
PyErr_SetString(PyExc_ValueError,
5858
"Key of option dict should be 32-bit signed int value.");
5959
return -1;
6060
}
6161

62-
const int value_v = _PyLong_AsInt(value);
62+
const int value_v = PyLong_AsInt(value);
6363
if (value_v == -1 && PyErr_Occurred()) {
6464
PyErr_SetString(PyExc_ValueError,
6565
"Value of option dict should be 32-bit signed int value.");
@@ -125,7 +125,7 @@ PYZSTD_FUN_PREFIX(load_c_dict)(PYZSTD_C_CLASS *self, PyObject *dict)
125125
return -1;
126126
} else if (ret > 0) {
127127
/* type == -1 may indicate an error. */
128-
type = _PyLong_AsInt(PyTuple_GET_ITEM(dict, 1));
128+
type = PyLong_AsInt(PyTuple_GET_ITEM(dict, 1));
129129
if (type == DICT_TYPE_DIGESTED ||
130130
type == DICT_TYPE_UNDIGESTED ||
131131
type == DICT_TYPE_PREFIX)
@@ -206,14 +206,14 @@ PYZSTD_FUN_PREFIX(set_d_parameters)(PYZSTD_D_CLASS *self, PyObject *option)
206206
}
207207

208208
/* Both key & value should be 32-bit signed int */
209-
const int key_v = _PyLong_AsInt(key);
209+
const int key_v = PyLong_AsInt(key);
210210
if (key_v == -1 && PyErr_Occurred()) {
211211
PyErr_SetString(PyExc_ValueError,
212212
"Key of option dict should be 32-bit signed integer value.");
213213
return -1;
214214
}
215215

216-
const int value_v = _PyLong_AsInt(value);
216+
const int value_v = PyLong_AsInt(value);
217217
if (value_v == -1 && PyErr_Occurred()) {
218218
PyErr_SetString(PyExc_ValueError,
219219
"Value of option dict should be 32-bit signed integer value.");
@@ -261,7 +261,7 @@ PYZSTD_FUN_PREFIX(load_d_dict)(PYZSTD_D_CLASS *self, PyObject *dict)
261261
return -1;
262262
} else if (ret > 0) {
263263
/* type == -1 may indicate an error. */
264-
type = _PyLong_AsInt(PyTuple_GET_ITEM(dict, 1));
264+
type = PyLong_AsInt(PyTuple_GET_ITEM(dict, 1));
265265
if (type == DICT_TYPE_DIGESTED ||
266266
type == DICT_TYPE_UNDIGESTED ||
267267
type == DICT_TYPE_PREFIX)

src/bin_ext/pyzstd.h

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
#define Py_UNREACHABLE() assert(0)
2222
#endif
2323

24+
#if PY_VERSION_HEX < 0x030D0000
25+
/* PyLong_AsInt() function is available on Python 3.13+ */
26+
#define PyLong_AsInt _PyLong_AsInt
27+
#endif
28+
2429
/* Multi-phase init (PEP-489) */
2530
#if PY_VERSION_HEX < 0x030B00B1 && defined(USE_MULTI_PHASE_INIT)
2631
/* PyType_GetModuleByDef() function is available on CPython 3.11+.

0 commit comments

Comments
 (0)