intobject.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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((op)->ob_type, Py_TPFLAGS_INT_SUBCLASS)
  24. #define PyInt_CheckExact(op) ((op)->ob_type == &PyInt_Type)
  25. PyAPI_FUNC(PyObject *) PyInt_FromString(char*, char**, int);
  26. #ifdef Py_USING_UNICODE
  27. PyAPI_FUNC(PyObject *) PyInt_FromUnicode(Py_UNICODE*, Py_ssize_t, int);
  28. #endif
  29. PyAPI_FUNC(PyObject *) PyInt_FromLong(long);
  30. PyAPI_FUNC(PyObject *) PyInt_FromSize_t(size_t);
  31. PyAPI_FUNC(PyObject *) PyInt_FromSsize_t(Py_ssize_t);
  32. PyAPI_FUNC(long) PyInt_AsLong(PyObject *);
  33. PyAPI_FUNC(Py_ssize_t) PyInt_AsSsize_t(PyObject *);
  34. PyAPI_FUNC(int) _PyInt_AsInt(PyObject *);
  35. PyAPI_FUNC(unsigned long) PyInt_AsUnsignedLongMask(PyObject *);
  36. #ifdef HAVE_LONG_LONG
  37. PyAPI_FUNC(unsigned PY_LONG_LONG) PyInt_AsUnsignedLongLongMask(PyObject *);
  38. #endif
  39. PyAPI_FUNC(long) PyInt_GetMax(void);
  40. /* Macro, trading safety for speed */
  41. #define PyInt_AS_LONG(op) (((PyIntObject *)(op))->ob_ival)
  42. /* These aren't really part of the Int object, but they're handy; the protos
  43. * are necessary for systems that need the magic of PyAPI_FUNC and that want
  44. * to have stropmodule as a dynamically loaded module instead of building it
  45. * into the main Python shared library/DLL. Guido thinks I'm weird for
  46. * building it this way. :-) [cjh]
  47. */
  48. PyAPI_FUNC(unsigned long) PyOS_strtoul(char *, char **, int);
  49. PyAPI_FUNC(long) PyOS_strtol(char *, char **, int);
  50. /* free list api */
  51. PyAPI_FUNC(int) PyInt_ClearFreeList(void);
  52. /* Convert an integer to the given base. Returns a string.
  53. If base is 2, 8 or 16, add the proper prefix '0b', '0o' or '0x'.
  54. If newstyle is zero, then use the pre-2.6 behavior of octal having
  55. a leading "0" */
  56. PyAPI_FUNC(PyObject*) _PyInt_Format(PyIntObject* v, int base, int newstyle);
  57. /* Format the object based on the format_spec, as defined in PEP 3101
  58. (Advanced String Formatting). */
  59. PyAPI_FUNC(PyObject *) _PyInt_FormatAdvanced(PyObject *obj,
  60. char *format_spec,
  61. Py_ssize_t format_spec_len);
  62. #ifdef __cplusplus
  63. }
  64. #endif
  65. #endif /* !Py_INTOBJECT_H */