Skip to content

Commit 428353c

Browse files
committed
fix: Python 3.13 added the PyLong_AsNativeBytes API, but changed the function signature of the _PyLong_AsByteArray API
See python/cpython#111140 and capi-workgroup/decisions#31
1 parent e4a4fda commit 428353c

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/IntType.cc

+4
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,11 @@ JS::BigInt *IntType::toJsBigInt(JSContext *cx, PyObject *pyObject) {
139139
// Convert to bytes of 8-bit "digits" in **big-endian** order
140140
size_t byteCount = (size_t)JS_DIGIT_BYTE * jsDigitCount;
141141
uint8_t *bytes = (uint8_t *)PyMem_Malloc(byteCount);
142+
#if PY_VERSION_HEX >= 0x030d0000 // Python version is greater than 3.13
143+
_PyLong_AsByteArray((PyLongObject *)pyObject, bytes, byteCount, /*is_little_endian*/ false, false, false);
144+
#else
142145
_PyLong_AsByteArray((PyLongObject *)pyObject, bytes, byteCount, /*is_little_endian*/ false, false);
146+
#endif
143147

144148
// Convert pm.bigint to JS::BigInt through hex strings (no public API to convert directly through bytes)
145149
// 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

0 commit comments

Comments
 (0)