Skip to content

Commit

Permalink
fix: Python 3.13 added the PyLong_AsNativeBytes API, but changed th…
Browse files Browse the repository at this point in the history
…e function signature of the `_PyLong_AsByteArray` API

See python/cpython#111140 and capi-workgroup/decisions#31
  • Loading branch information
Xmader committed Aug 22, 2024
1 parent e4a4fda commit 428353c
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/IntType.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,11 @@ JS::BigInt *IntType::toJsBigInt(JSContext *cx, PyObject *pyObject) {
// Convert to bytes of 8-bit "digits" in **big-endian** order
size_t byteCount = (size_t)JS_DIGIT_BYTE * jsDigitCount;
uint8_t *bytes = (uint8_t *)PyMem_Malloc(byteCount);
#if PY_VERSION_HEX >= 0x030d0000 // Python version is greater than 3.13
_PyLong_AsByteArray((PyLongObject *)pyObject, bytes, byteCount, /*is_little_endian*/ false, false, false);
#else
_PyLong_AsByteArray((PyLongObject *)pyObject, bytes, byteCount, /*is_little_endian*/ false, false);
#endif

// Convert pm.bigint to JS::BigInt through hex strings (no public API to convert directly through bytes)
// TODO (Tom Tang): We could manually allocate the memory, https://hg.mozilla.org/releases/mozilla-esr102/file/tip/js/src/vm/BigIntType.cpp#l162, but still no public API
Expand Down

0 comments on commit 428353c

Please sign in to comment.