17#if PY_VERSION_HEX >= 0x030C0000
19 #define tt_GET_OB_DIGIT(obj) obj->long_value.ob_digit
20 #define tt_SET_OB_DIGIT(obj, n) obj->long_value.lv_tag = (n << 3) | (obj->long_value.lv_tag & 3)
21 #define tt_PyLong_IsNegative(obj) ((obj->long_value.lv_tag & 3) == 2)
22 #define tt_PyLong_DigitCount(obj) (obj->long_value.lv_tag >> 3)
24#elif PY_VERSION_HEX >= 0X030A00F0
26 #define tt_GET_OB_DIGIT(obj) obj->ob_digit
27 #define tt_SET_OB_DIGIT(obj, n) Py_SET_SIZE(obj, n)
28 #define tt_PyLong_IsNegative(obj) (Py_SIZE(obj) < 0)
29 #define tt_PyLong_DigitCount(obj) (tt_PyLong_IsNegative(obj) ? -Py_SIZE(obj) : Py_SIZE(obj))
33 #define tt_GET_OB_DIGIT(obj) obj->ob_digit
34 #define tt_SET_OB_DIGIT(obj, n) Py_SIZE(obj) = n
35 #define tt_PyLong_IsNegative(obj) (Py_SIZE(obj) < 0)
36 #define tt_PyLong_DigitCount(obj) (tt_PyLong_IsNegative(obj) ? -Py_SIZE(obj) : Py_SIZE(obj))
46 return (PyObject_IsTrue(obj) != 0);
52 PyLongObject* v =
nullptr;
56 if (vv == NULL || !PyLong_Check(vv)) {
57 if (vv != NULL && PyInt_Check(vv)) {
58 return PyInt_AsLong(vv);
63 v =
reinterpret_cast<PyLongObject*
>(vv);
64 n = tt_PyLong_IsNegative(v);
65 i = tt_PyLong_DigitCount(v);
70 x = (x << PyLong_SHIFT) | tt_GET_OB_DIGIT(v)[i];
71 if ((x >> PyLong_SHIFT) != prev)
75 return (n ? ((~x)+1) : x);
81 PyLongObject* v =
nullptr;
85 if (vv == NULL || !PyLong_Check(vv)) {
86 if (vv != NULL && PyInt_Check(vv)) {
87 return PyInt_AsLong(vv);
92 v =
reinterpret_cast<PyLongObject*
>(vv);
93 n = tt_PyLong_IsNegative(v);
94 i = tt_PyLong_DigitCount(v);
99 x = (x << PyLong_SHIFT) | tt_GET_OB_DIGIT(v)[i];
100 if ((x >> PyLong_SHIFT) != prev)
104 return (n ? ((~x)+1) : x);
110 PyLongObject* v =
nullptr;
114 if (vv == NULL || !PyLong_Check(vv)) {
115 if (vv != NULL && PyInt_Check(vv)) {
116 return PyInt_AsLong(vv);
121 v =
reinterpret_cast<PyLongObject*
>(vv);
122 n = tt_PyLong_IsNegative(v);
123 i = tt_PyLong_DigitCount(v);
128 x = (x << PyLong_SHIFT) | tt_GET_OB_DIGIT(v)[i];
129 if ((x >> PyLong_SHIFT) != prev)
133 return (n ? ((~x)+1) : x);
139 PyLongObject* v =
nullptr;
143 if (vv == NULL || !PyLong_Check(vv)) {
144 if (vv != NULL && PyInt_Check(vv)) {
145 return PyInt_AsLong(vv);
150 v =
reinterpret_cast<PyLongObject*
>(vv);
151 n = tt_PyLong_IsNegative(v);
152 i = tt_PyLong_DigitCount(v);
157 x = (x << PyLong_SHIFT) | tt_GET_OB_DIGIT(v)[i];
158 if ((x >> PyLong_SHIFT) != prev)
162 return (n ? ((~x)+1) : x);
168 PyLongObject* v =
nullptr;
172 if (vv == NULL || !PyLong_Check(vv)) {
173 if (vv != NULL && PyInt_Check(vv)) {
174 return PyInt_AsLong(vv);
179 v =
reinterpret_cast<PyLongObject*
>(vv);
180 n = tt_PyLong_IsNegative(v);
181 i = tt_PyLong_DigitCount(v);
186 x = (x << PyLong_SHIFT) | tt_GET_OB_DIGIT(v)[i];
187 if ((x >> PyLong_SHIFT) != prev)
191 return (n ? ((~x)+1) : x);
197 PyLongObject* v =
nullptr;
201 if (vv == NULL || !PyLong_Check(vv)) {
202 if (vv != NULL && PyInt_Check(vv)) {
203 return PyInt_AsLong(vv);
208 v =
reinterpret_cast<PyLongObject*
>(vv);
209 n = tt_PyLong_IsNegative(v);
210 i = tt_PyLong_DigitCount(v);
215 x = (x << PyLong_SHIFT) | tt_GET_OB_DIGIT(v)[i];
216 if ((x >> PyLong_SHIFT) != prev)
220 return (n ? ((~x)+1) : x);
226 PyLongObject* v =
nullptr;
230 if (vv == NULL || !PyLong_Check(vv)) {
231 if (vv != NULL && PyInt_Check(vv)) {
232 return PyInt_AsLong(vv);
237 v =
reinterpret_cast<PyLongObject*
>(vv);
238 n = tt_PyLong_IsNegative(v);
239 i = tt_PyLong_DigitCount(v);
244 x = (x << PyLong_SHIFT) | tt_GET_OB_DIGIT(v)[i];
245 if ((x >> PyLong_SHIFT) != prev)
249 return (n ? ((~x)+1) : x);
255 #if defined(__i386) || defined(_M_IX86)
256 return PyInt_FromLong(
static_cast<long>(value));
263 if (value <= std::numeric_limits<long>::max())
264 return PyInt_FromLong(
static_cast<long>(value));
273 v = _PyLong_New(ndigits);
274 digit* p = tt_GET_OB_DIGIT(v);
275 tt_SET_OB_DIGIT(v, ndigits);
278 *p++ =
static_cast<digit
>(value & PyLong_MASK);
279 value >>= PyLong_SHIFT;
289 #if defined(__i386) || defined(_M_IX86)
290 return PyInt_FromLong(
static_cast<long>(value));
297 if (value <= std::numeric_limits<long>::max())
298 return PyInt_FromLong(
static_cast<long>(value));
307 v = _PyLong_New(ndigits);
308 digit* p = tt_GET_OB_DIGIT(v);
309 tt_SET_OB_DIGIT(v, ndigits);
312 *p++ =
static_cast<digit
>(value & PyLong_MASK);
313 value >>= PyLong_SHIFT;
323 return PyInt_FromLong(
static_cast<long>(value));
334 if (value <= std::numeric_limits<long>::max())
335 return PyInt_FromLong(
static_cast<long>(value));
344 v = _PyLong_New(ndigits);
345 digit* p = tt_GET_OB_DIGIT(v);
346 tt_SET_OB_DIGIT(v, ndigits);
349 *p++ =
static_cast<digit
>(value & PyLong_MASK);
350 value >>= PyLong_SHIFT;
364 if (value <= std::numeric_limits<long>::max())
365 return PyInt_FromLong(
static_cast<long>(value));
374 v = _PyLong_New(ndigits);
375 digit* p = tt_GET_OB_DIGIT(v);
376 tt_SET_OB_DIGIT(v, ndigits);
379 *p++ =
static_cast<digit
>(value & PyLong_MASK);
380 value >>= PyLong_SHIFT;
394 if (value <= std::numeric_limits<long>::max())
395 return PyInt_FromLong(
static_cast<long>(value));
404 v = _PyLong_New(ndigits);
405 digit* p = tt_GET_OB_DIGIT(v);
406 tt_SET_OB_DIGIT(v, ndigits);
409 *p++ =
static_cast<digit
>(value & PyLong_MASK);
410 value >>= PyLong_SHIFT;
424 if (value <= std::numeric_limits<long>::max())
425 return PyInt_FromLong(
static_cast<long>(value));
434 v = _PyLong_New(ndigits);
435 digit* p = tt_GET_OB_DIGIT(v);
436 tt_SET_OB_DIGIT(v, ndigits);
439 *p++ =
static_cast<digit
>(value & PyLong_MASK);
440 value >>= PyLong_SHIFT;
450#undef tt_GET_OB_DIGIT
451#undef tt_SET_OB_DIGIT
452#undef tt_PyLong_IsNegative
453#undef tt_PyLong_DigitCount
The exception class used by bindings.
PyObject * PyLong_FromUint(triton::__uint value)
Returns a pyObject from a triton::__uint.
triton::uint64 PyLong_AsUint64(PyObject *vv)
Returns a triton::uint64 from a pyObject.
triton::uint128 PyLong_AsUint128(PyObject *vv)
Returns a triton::uint128 from a pyObject.
PyObject * PyLong_FromUsize(triton::usize value)
Returns a pyObject from a triton::usize.
triton::__uint PyLong_AsUint(PyObject *vv)
Returns a triton::__uint from a pyObject.
PyObject * PyLong_FromUint256(triton::uint256 value)
Returns a pyObject from a triton::uint256.
bool PyLong_AsBool(PyObject *obj)
Returns a bool from a pyObject.
PyObject * PyLong_FromUint512(triton::uint512 value)
Returns a pyObject from a triton::uint512.
triton::uint512 PyLong_AsUint512(PyObject *vv)
Returns a triton::uint512 from a pyObject.
triton::uint256 PyLong_AsUint256(PyObject *vv)
Returns a triton::uint256 from a pyObject.
PyObject * PyLong_FromUint64(triton::uint64 value)
Returns a pyObject from a triton::uint64.
triton::uint32 PyLong_AsUint32(PyObject *vv)
Returns a triton::uint32 from a pyObject.
triton::usize PyLong_AsUsize(PyObject *vv)
Returns a triton::usize from a pyObject.
PyObject * PyLong_FromUint128(triton::uint128 value)
Returns a pyObject from a triton::uint128.
PyObject * PyLong_FromUint32(triton::uint32 value)
Returns a pyObject from a triton::uint32.
std::size_t usize
unsigned MAX_INT 32 or 64 bits according to the CPU.
std::uint64_t uint64
unisgned 64-bits
std::uint32_t uint32
unisgned 32-bits
unsigned long long __uint
unsigned long long if the arch is 64-bits.