|
14 | 14 | #include <jsapi.h>
|
15 | 15 | #include <js/BigInt.h>
|
16 | 16 |
|
| 17 | +#include <Python.h> |
| 18 | +#include "include/pyshim.hh" |
| 19 | + |
17 | 20 | #include <vector>
|
18 | 21 |
|
19 | 22 | #define SIGN_BIT_MASK 0b1000 // https://hg.mozilla.org/releases/mozilla-esr102/file/tip/js/src/vm/BigIntType.h#l40
|
@@ -44,11 +47,7 @@ static inline void PythonLong_SetSign(PyLongObject *op, int sign) {
|
44 | 47 | #else // Python version is less than 3.12
|
45 | 48 | // see https://github.com/python/cpython/blob/v3.9.16/Objects/longobject.c#L956
|
46 | 49 | Py_ssize_t pyDigitCount = Py_SIZE(op);
|
47 |
| - #if PY_VERSION_HEX >= 0x03090000 |
48 | 50 | Py_SET_SIZE(op, sign * std::abs(pyDigitCount));
|
49 |
| - #else |
50 |
| - ((PyVarObject *)op)->ob_size = sign * std::abs(pyDigitCount); // Py_SET_SIZE is not available in Python < 3.9 |
51 |
| - #endif |
52 | 51 | #endif
|
53 | 52 | }
|
54 | 53 |
|
@@ -102,11 +101,7 @@ PyObject *IntType::getPyObject(JSContext *cx, JS::BigInt *bigint) {
|
102 | 101 | // Cast to a pythonmonkey.bigint to differentiate it from a normal Python int,
|
103 | 102 | // allowing Py<->JS two-way BigInt conversion.
|
104 | 103 | // We don't do `Py_SET_TYPE` because `_PyLong_FromByteArray` may cache and reuse objects for small ints
|
105 |
| - #if PY_VERSION_HEX >= 0x03090000 |
106 | 104 | PyObject *pyObject = PyObject_CallOneArg(getPythonMonkeyBigInt(), pyIntObj); // pyObject = pythonmonkey.bigint(pyIntObj)
|
107 |
| - #else |
108 |
| - PyObject *pyObject = PyObject_CallFunction(getPythonMonkeyBigInt(), "O", pyIntObj); // PyObject_CallOneArg is not available in Python < 3.9 |
109 |
| - #endif |
110 | 105 | Py_DECREF(pyIntObj);
|
111 | 106 |
|
112 | 107 | // Set the sign bit
|
@@ -139,11 +134,7 @@ JS::BigInt *IntType::toJsBigInt(JSContext *cx, PyObject *pyObject) {
|
139 | 134 | // Convert to bytes of 8-bit "digits" in **big-endian** order
|
140 | 135 | size_t byteCount = (size_t)JS_DIGIT_BYTE * jsDigitCount;
|
141 | 136 | 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 |
145 |
| - _PyLong_AsByteArray((PyLongObject *)pyObject, bytes, byteCount, /*is_little_endian*/ false, false); |
146 |
| - #endif |
| 137 | + PyLong_AsByteArray((PyLongObject *)pyObject, bytes, byteCount, /*is_little_endian*/ false, false); |
147 | 138 |
|
148 | 139 | // Convert pm.bigint to JS::BigInt through hex strings (no public API to convert directly through bytes)
|
149 | 140 | // 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