diff --git a/bindings/python/NumericBindings.cpp b/bindings/python/NumericBindings.cpp index d80a70006..659d467a8 100644 --- a/bindings/python/NumericBindings.cpp +++ b/bindings/python/NumericBindings.cpp @@ -32,8 +32,17 @@ static SVInt SVIntFromPyInt(const py::int_& value) { size_t numBytes = ((bits - 1) / 32 + 1) * 4; std::vector mem(numBytes); - int r = _PyLong_AsByteArray(reinterpret_cast(value.ptr()), - reinterpret_cast(mem.data()), numBytes, 1, 1); + int r = -1; +#if PY_VERSION_HEX < 0x030D0000 + r = _PyLong_AsByteArray(reinterpret_cast(value.ptr()), + reinterpret_cast(mem.data()), numBytes, 1, 1); +#else + // fix build error with python 3.13 + r = _PyLong_AsByteArray(reinterpret_cast(value.ptr()), + reinterpret_cast(mem.data()), numBytes, 1, 1, 0); + // No exception is thrown here because it will be done later. +#endif + if (r == -1) throw py::error_already_set();