Skip to content

Commit

Permalink
chore: replace _PyLong_AsInt() with PyLong_AsInt()
Browse files Browse the repository at this point in the history
Context in python/cpython#108444

Signed-off-by: Mikel Olasagasti Uranga <mikel@olasagasti.info>
  • Loading branch information
mikelolasagasti authored and Rogdham committed Jun 16, 2024
1 parent 90f783e commit fb8efdd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/bin_ext/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ ZstdFileWriter_flush(ZstdFileWriter *self, PyObject *arg)
STATE_FROM_OBJ(self);

/* Mode argument */
mode = _PyLong_AsInt(arg);
mode = PyLong_AsInt(arg);

assert(ZSTD_e_flush == 1 && ZSTD_e_end == 2);
if (mode != ZSTD_e_flush && mode != ZSTD_e_end) {
Expand Down
14 changes: 7 additions & 7 deletions src/bin_ext/macro_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ PYZSTD_FUN_PREFIX(set_c_parameters)(PYZSTD_C_CLASS *self, PyObject *level_or_opt

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

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

const int value_v = _PyLong_AsInt(value);
const int value_v = PyLong_AsInt(value);
if (value_v == -1 && PyErr_Occurred()) {
PyErr_SetString(PyExc_ValueError,
"Value of option dict should be 32-bit signed int value.");
Expand Down Expand Up @@ -125,7 +125,7 @@ PYZSTD_FUN_PREFIX(load_c_dict)(PYZSTD_C_CLASS *self, PyObject *dict)
return -1;
} else if (ret > 0) {
/* type == -1 may indicate an error. */
type = _PyLong_AsInt(PyTuple_GET_ITEM(dict, 1));
type = PyLong_AsInt(PyTuple_GET_ITEM(dict, 1));
if (type == DICT_TYPE_DIGESTED ||
type == DICT_TYPE_UNDIGESTED ||
type == DICT_TYPE_PREFIX)
Expand Down Expand Up @@ -206,14 +206,14 @@ PYZSTD_FUN_PREFIX(set_d_parameters)(PYZSTD_D_CLASS *self, PyObject *option)
}

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

const int value_v = _PyLong_AsInt(value);
const int value_v = PyLong_AsInt(value);
if (value_v == -1 && PyErr_Occurred()) {
PyErr_SetString(PyExc_ValueError,
"Value of option dict should be 32-bit signed integer value.");
Expand Down Expand Up @@ -261,7 +261,7 @@ PYZSTD_FUN_PREFIX(load_d_dict)(PYZSTD_D_CLASS *self, PyObject *dict)
return -1;
} else if (ret > 0) {
/* type == -1 may indicate an error. */
type = _PyLong_AsInt(PyTuple_GET_ITEM(dict, 1));
type = PyLong_AsInt(PyTuple_GET_ITEM(dict, 1));
if (type == DICT_TYPE_DIGESTED ||
type == DICT_TYPE_UNDIGESTED ||
type == DICT_TYPE_PREFIX)
Expand Down
5 changes: 5 additions & 0 deletions src/bin_ext/pyzstd.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
#define Py_UNREACHABLE() assert(0)
#endif

/* Added in Python 3.13 */
#if PY_VERSION_HEX < 0x030D00A1
#define PyLong_AsInt _PyLong_AsInt
#endif

/* Multi-phase init (PEP-489) */
#if PY_VERSION_HEX < 0x030B00B1 && defined(USE_MULTI_PHASE_INIT)
/* PyType_GetModuleByDef() function is available on CPython 3.11+.
Expand Down

0 comments on commit fb8efdd

Please sign in to comment.