longobject.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #ifndef Py_LONGOBJECT_H
  2. #define Py_LONGOBJECT_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. /* Long (arbitrary precision) integer object interface */
  7. PyAPI_DATA(PyTypeObject) PyLong_Type;
  8. #define PyLong_Check(op) \
  9. PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LONG_SUBCLASS)
  10. #define PyLong_CheckExact(op) Py_IS_TYPE((op), &PyLong_Type)
  11. PyAPI_FUNC(PyObject *) PyLong_FromLong(long);
  12. PyAPI_FUNC(PyObject *) PyLong_FromUnsignedLong(unsigned long);
  13. PyAPI_FUNC(PyObject *) PyLong_FromSize_t(size_t);
  14. PyAPI_FUNC(PyObject *) PyLong_FromSsize_t(Py_ssize_t);
  15. PyAPI_FUNC(PyObject *) PyLong_FromDouble(double);
  16. PyAPI_FUNC(long) PyLong_AsLong(PyObject *);
  17. PyAPI_FUNC(long) PyLong_AsLongAndOverflow(PyObject *, int *);
  18. PyAPI_FUNC(Py_ssize_t) PyLong_AsSsize_t(PyObject *);
  19. PyAPI_FUNC(size_t) PyLong_AsSize_t(PyObject *);
  20. PyAPI_FUNC(unsigned long) PyLong_AsUnsignedLong(PyObject *);
  21. PyAPI_FUNC(unsigned long) PyLong_AsUnsignedLongMask(PyObject *);
  22. PyAPI_FUNC(PyObject *) PyLong_GetInfo(void);
  23. /* It may be useful in the future. I've added it in the PyInt -> PyLong
  24. cleanup to keep the extra information. [CH] */
  25. #define PyLong_AS_LONG(op) PyLong_AsLong(op)
  26. /* Issue #1983: pid_t can be longer than a C long on some systems */
  27. #if !defined(SIZEOF_PID_T) || SIZEOF_PID_T == SIZEOF_INT
  28. #define _Py_PARSE_PID "i"
  29. #define PyLong_FromPid PyLong_FromLong
  30. #define PyLong_AsPid PyLong_AsLong
  31. #elif SIZEOF_PID_T == SIZEOF_LONG
  32. #define _Py_PARSE_PID "l"
  33. #define PyLong_FromPid PyLong_FromLong
  34. #define PyLong_AsPid PyLong_AsLong
  35. #elif defined(SIZEOF_LONG_LONG) && SIZEOF_PID_T == SIZEOF_LONG_LONG
  36. #define _Py_PARSE_PID "L"
  37. #define PyLong_FromPid PyLong_FromLongLong
  38. #define PyLong_AsPid PyLong_AsLongLong
  39. #else
  40. #error "sizeof(pid_t) is neither sizeof(int), sizeof(long) or sizeof(long long)"
  41. #endif /* SIZEOF_PID_T */
  42. #if SIZEOF_VOID_P == SIZEOF_INT
  43. # define _Py_PARSE_INTPTR "i"
  44. # define _Py_PARSE_UINTPTR "I"
  45. #elif SIZEOF_VOID_P == SIZEOF_LONG
  46. # define _Py_PARSE_INTPTR "l"
  47. # define _Py_PARSE_UINTPTR "k"
  48. #elif defined(SIZEOF_LONG_LONG) && SIZEOF_VOID_P == SIZEOF_LONG_LONG
  49. # define _Py_PARSE_INTPTR "L"
  50. # define _Py_PARSE_UINTPTR "K"
  51. #else
  52. # error "void* different in size from int, long and long long"
  53. #endif /* SIZEOF_VOID_P */
  54. PyAPI_FUNC(double) PyLong_AsDouble(PyObject *);
  55. PyAPI_FUNC(PyObject *) PyLong_FromVoidPtr(void *);
  56. PyAPI_FUNC(void *) PyLong_AsVoidPtr(PyObject *);
  57. PyAPI_FUNC(PyObject *) PyLong_FromLongLong(long long);
  58. PyAPI_FUNC(PyObject *) PyLong_FromUnsignedLongLong(unsigned long long);
  59. PyAPI_FUNC(long long) PyLong_AsLongLong(PyObject *);
  60. PyAPI_FUNC(unsigned long long) PyLong_AsUnsignedLongLong(PyObject *);
  61. PyAPI_FUNC(unsigned long long) PyLong_AsUnsignedLongLongMask(PyObject *);
  62. PyAPI_FUNC(long long) PyLong_AsLongLongAndOverflow(PyObject *, int *);
  63. PyAPI_FUNC(PyObject *) PyLong_FromString(const char *, char **, int);
  64. /* These aren't really part of the int object, but they're handy. The
  65. functions are in Python/mystrtoul.c.
  66. */
  67. PyAPI_FUNC(unsigned long) PyOS_strtoul(const char *, char **, int);
  68. PyAPI_FUNC(long) PyOS_strtol(const char *, char **, int);
  69. #ifndef Py_LIMITED_API
  70. # define Py_CPYTHON_LONGOBJECT_H
  71. # include "cpython/longobject.h"
  72. # undef Py_CPYTHON_LONGOBJECT_H
  73. #endif
  74. #ifdef __cplusplus
  75. }
  76. #endif
  77. #endif /* !Py_LONGOBJECT_H */