long.pxd 6.9 KB

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