In Python2's C API there was long PyInt_AS_LONG()
function which allowed a very quick creation of a C long
from a Python2 int
.
Is there a quick way to check, using Python3 C API, that an int
(which is actually an arbitrary precision integer) fits into C long
?
One can call PyLong_AsLong()
, but this appears to do unnecessary work. There ought to be a function to get the size of the memory block used to store the number, but I can't find anything in the docs.
This has to be done in C, so I can't directly use Python arithmetic comparison. Although I can, in principle, call PyObject_RichCompare(), it looks like an overkill.