intobject.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* Integer object interface */
  2. /*
  3. PyIntObject represents a (long) integer. This is an immutable object;
  4. an integer cannot change its value after creation.
  5. There are functions to create new integer objects, to test an object
  6. for integer-ness, and to get the integer value. The latter functions
  7. returns -1 and sets errno to EBADF if the object is not an PyIntObject.
  8. None of the functions should be applied to nil objects.
  9. The type PyIntObject is (unfortunately) exposed here so we can declare
  10. _Py_TrueStruct and _Py_ZeroStruct in boolobject.h; don't use this.
  11. */
  12. #ifndef Py_INTOBJECT_H
  13. #define Py_INTOBJECT_H
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. typedef struct {
  18. PyObject_HEAD
  19. long ob_ival;
  20. } PyIntObject;
  21. PyAPI_DATA(PyTypeObject) PyInt_Type;
  22. #define PyInt_Check(op) \
  23. PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_INT_SUBCLASS)
  24. #define PyInt_CheckExact(op) (Py_TYPE(op) == &PyInt_Type)
  25. #define _PyAnyInt_Check(op) (PyInt_Check(op) || PyLong_Check(op))
  26. #define _PyAnyInt_CheckExact(op) (PyInt_CheckExact(op) || PyLong_CheckExact(op))
  27. PyAPI_FUNC(PyObject *) PyInt_FromString(char*, char**, int);
  28. #ifdef Py_USING_UNICODE
  29. PyAPI_FUNC(PyObject *) PyInt_FromUnicode(Py_UNICODE*, Py_ssize_t, int);
  30. #endif
  31. PyAPI_FUNC(PyObject *) PyInt_FromLong(long);
  32. PyAPI_FUNC(PyObject *) PyInt_FromSize_t(size_t);
  33. PyAPI_FUNC(PyObject *) PyInt_FromSsize_t(Py_ssize_t);
  34. PyAPI_FUNC(long) PyInt_AsLong(PyObject *);
  35. PyAPI_FUNC(Py_ssize_t) PyInt_AsSsize_t(PyObject *);
  36. PyAPI_FUNC(int) _PyInt_AsInt(PyObject *);
  37. PyAPI_FUNC(unsigned long) PyInt_AsUnsignedLongMask(PyObject *);
  38. #ifdef HAVE_LONG_LONG
  39. PyAPI_FUNC(unsigned PY_LONG_LONG) PyInt_AsUnsignedLongLongMask(PyObject *);
  40. #endif
  41. PyAPI_FUNC(long) PyInt_GetMax(void);
  42. /* Macro, trading safety for speed */
  43. #define PyInt_AS_LONG(op) (((PyIntObject *)(op))->ob_ival)
  44. /* These aren't really part of the Int object, but they're handy; the protos
  45. * are necessary for systems that need the magic of PyAPI_FUNC and that want
  46. * to have stropmodule as a dynamically loaded module instead of building it
  47. * into the main Python shared library/DLL. Guido thinks I'm weird for
  48. * building it this way. :-) [cjh]
  49. */
  50. PyAPI_FUNC(unsigned long) PyOS_strtoul(char *, char **, int);
  51. PyAPI_FUNC(long) PyOS_strtol(char *, char **, int);
  52. /* free list api */
  53. PyAPI_FUNC(int) PyInt_ClearFreeList(void);
  54. /* Convert an integer to the given base. Returns a string.
  55. If base is 2, 8 or 16, add the proper prefix '0b', '0o' or '0x'.
  56. If newstyle is zero, then use the pre-2.6 behavior of octal having
  57. a leading "0" */
  58. PyAPI_FUNC(PyObject*) _PyInt_Format(PyIntObject* v, int base, int newstyle);
  59. /* Format the object based on the format_spec, as defined in PEP 3101
  60. (Advanced String Formatting). */
  61. PyAPI_FUNC(PyObject *) _PyInt_FormatAdvanced(PyObject *obj,
  62. char *format_spec,
  63. Py_ssize_t format_spec_len);
  64. #ifdef __cplusplus
  65. }
  66. #endif
  67. #endif /* !Py_INTOBJECT_H */