1 2 cdef extern from "Python.h": 3 ctypedef long long PY_LONG_LONG 4 ctypedef unsigned long long uPY_LONG_LONG "unsigned PY_LONG_LONG" 5 6 ############################################################################ 7 # 7.2.3 Long Integer Objects 8 ############################################################################ 9 10 # PyLongObject 11 # 12 # This subtype of PyObject represents a Python long integer object. 13 14 # PyTypeObject PyLong_Type 15 # 16 # This instance of PyTypeObject represents the Python long integer 17 # type. This is the same object as long and types.LongType. 18 19 bint PyLong_Check(object p) 20 # Return true if its argument is a PyLongObject or a subtype of PyLongObject. 21 22 bint PyLong_CheckExact(object p) 23 # Return true if its argument is a PyLongObject, but not a subtype of PyLongObject. 24 25 object PyLong_FromLong(long v) 26 # Return value: New reference. 27 # Return a new PyLongObject object from v, or NULL on failure. 28 29 object PyLong_FromUnsignedLong(unsigned long v) 30 # Return value: New reference. 31 # Return a new PyLongObject object from a C unsigned long, or NULL on failure. 32 33 object PyLong_FromLongLong(PY_LONG_LONG v) 34 # Return value: New reference. 35 # Return a new PyLongObject object from a C long long, or NULL on failure. 36 37 object PyLong_FromUnsignedLongLong(uPY_LONG_LONG v) 38 # Return value: New reference. 39 # Return a new PyLongObject object from a C unsigned long long, or NULL on failure. 40 41 object PyLong_FromDouble(double v) 42 # Return value: New reference. 43 # Return a new PyLongObject object from the integer part of v, or NULL on failure. 44 45 object PyLong_FromString(char *str, char **pend, int base) 46 # Return value: New reference. 47 # Return a new PyLongObject based on the string value in str, 48 # which is interpreted according to the radix in base. If pend is 49 # non-NULL, *pend will point to the first character in str which 50 # follows the representation of the number. If base is 0, the 51 # radix will be determined based on the leading characters of str: 52 # if str starts with '0x' or '0X', radix 16 will be used; if str 53 # starts with '0', radix 8 will be used; otherwise radix 10 will 54 # be used. If base is not 0, it must be between 2 and 36, 55 # inclusive. Leading spaces are ignored. If there are no digits, 56 # ValueError will be raised. 57 58 object PyLong_FromUnicode(Py_UNICODE *u, Py_ssize_t length, int base) 59 # Return value: New reference. 60 # Convert a sequence of Unicode digits to a Python long integer 61 # value. The first parameter, u, points to the first character of 62 # the Unicode string, length gives the number of characters, and 63 # base is the radix for the conversion. The radix must be in the 64 # range [2, 36]; if it is out of range, ValueError will be 65 # raised. 66 67 object PyLong_FromVoidPtr(void *p) 68 # Return value: New reference. 69 # Create a Python integer or long integer from the pointer p. The 70 # pointer value can be retrieved from the resulting value using 71 # PyLong_AsVoidPtr(). If the integer is larger than LONG_MAX, a 72 # positive long integer is returned. 73 74 long PyLong_AsLong(object pylong) except? -1 75 # Return a C long representation of the contents of pylong. If 76 # pylong is greater than LONG_MAX, an OverflowError is raised. 77 78 unsigned long PyLong_AsUnsignedLong(object pylong) except? -1 79 # Return a C unsigned long representation of the contents of 80 # pylong. If pylong is greater than ULONG_MAX, an OverflowError is 81 # raised. 82 83 PY_LONG_LONG PyLong_AsLongLong(object pylong) except? -1 84 # Return a C long long from a Python long integer. If pylong 85 # cannot be represented as a long long, an OverflowError will be 86 # raised. 87 88 uPY_LONG_LONG PyLong_AsUnsignedLongLong(object pylong) except? -1 89 #unsigned PY_LONG_LONG PyLong_AsUnsignedLongLong(object pylong) 90 # Return a C unsigned long long from a Python long integer. If 91 # pylong cannot be represented as an unsigned long long, an 92 # OverflowError will be raised if the value is positive, or a 93 # TypeError will be raised if the value is negative. 94 95 unsigned long PyLong_AsUnsignedLongMask(object io) except? -1 96 # Return a C unsigned long from a Python long integer, without 97 # checking for overflow. 98 99 uPY_LONG_LONG PyLong_AsUnsignedLongLongMask(object io) except? -1 100 #unsigned PY_LONG_LONG PyLong_AsUnsignedLongLongMask(object io) 101 # Return a C unsigned long long from a Python long integer, 102 # without checking for overflow. 103 104 double PyLong_AsDouble(object pylong) except? -1.0 105 # Return a C double representation of the contents of pylong. If 106 # pylong cannot be approximately represented as a double, an 107 # OverflowError exception is raised and -1.0 will be returned. 108 109 void* PyLong_AsVoidPtr(object pylong) except? NULL 110 # Convert a Python integer or long integer pylong to a C void 111 # pointer. If pylong cannot be converted, an OverflowError will be 112 # raised. This is only assured to produce a usable void pointer 113 # for values created with PyLong_FromVoidPtr(). For values outside 114 # 0..LONG_MAX, both signed and unsigned integers are acccepted. 115