Chris@87: Chris@87: /* Integer object interface */ Chris@87: Chris@87: /* Chris@87: PyIntObject represents a (long) integer. This is an immutable object; Chris@87: an integer cannot change its value after creation. Chris@87: Chris@87: There are functions to create new integer objects, to test an object Chris@87: for integer-ness, and to get the integer value. The latter functions Chris@87: returns -1 and sets errno to EBADF if the object is not an PyIntObject. Chris@87: None of the functions should be applied to nil objects. Chris@87: Chris@87: The type PyIntObject is (unfortunately) exposed here so we can declare Chris@87: _Py_TrueStruct and _Py_ZeroStruct in boolobject.h; don't use this. Chris@87: */ Chris@87: Chris@87: #ifndef Py_INTOBJECT_H Chris@87: #define Py_INTOBJECT_H Chris@87: #ifdef __cplusplus Chris@87: extern "C" { Chris@87: #endif Chris@87: Chris@87: typedef struct { Chris@87: PyObject_HEAD Chris@87: long ob_ival; Chris@87: } PyIntObject; Chris@87: Chris@87: PyAPI_DATA(PyTypeObject) PyInt_Type; Chris@87: Chris@87: #define PyInt_Check(op) \ Chris@87: PyType_FastSubclass((op)->ob_type, Py_TPFLAGS_INT_SUBCLASS) Chris@87: #define PyInt_CheckExact(op) ((op)->ob_type == &PyInt_Type) Chris@87: Chris@87: PyAPI_FUNC(PyObject *) PyInt_FromString(char*, char**, int); Chris@87: #ifdef Py_USING_UNICODE Chris@87: PyAPI_FUNC(PyObject *) PyInt_FromUnicode(Py_UNICODE*, Py_ssize_t, int); Chris@87: #endif Chris@87: PyAPI_FUNC(PyObject *) PyInt_FromLong(long); Chris@87: PyAPI_FUNC(PyObject *) PyInt_FromSize_t(size_t); Chris@87: PyAPI_FUNC(PyObject *) PyInt_FromSsize_t(Py_ssize_t); Chris@87: PyAPI_FUNC(long) PyInt_AsLong(PyObject *); Chris@87: PyAPI_FUNC(Py_ssize_t) PyInt_AsSsize_t(PyObject *); Chris@87: PyAPI_FUNC(int) _PyInt_AsInt(PyObject *); Chris@87: PyAPI_FUNC(unsigned long) PyInt_AsUnsignedLongMask(PyObject *); Chris@87: #ifdef HAVE_LONG_LONG Chris@87: PyAPI_FUNC(unsigned PY_LONG_LONG) PyInt_AsUnsignedLongLongMask(PyObject *); Chris@87: #endif Chris@87: Chris@87: PyAPI_FUNC(long) PyInt_GetMax(void); Chris@87: Chris@87: /* Macro, trading safety for speed */ Chris@87: #define PyInt_AS_LONG(op) (((PyIntObject *)(op))->ob_ival) Chris@87: Chris@87: /* These aren't really part of the Int object, but they're handy; the protos Chris@87: * are necessary for systems that need the magic of PyAPI_FUNC and that want Chris@87: * to have stropmodule as a dynamically loaded module instead of building it Chris@87: * into the main Python shared library/DLL. Guido thinks I'm weird for Chris@87: * building it this way. :-) [cjh] Chris@87: */ Chris@87: PyAPI_FUNC(unsigned long) PyOS_strtoul(char *, char **, int); Chris@87: PyAPI_FUNC(long) PyOS_strtol(char *, char **, int); Chris@87: Chris@87: /* free list api */ Chris@87: PyAPI_FUNC(int) PyInt_ClearFreeList(void); Chris@87: Chris@87: /* Convert an integer to the given base. Returns a string. Chris@87: If base is 2, 8 or 16, add the proper prefix '0b', '0o' or '0x'. Chris@87: If newstyle is zero, then use the pre-2.6 behavior of octal having Chris@87: a leading "0" */ Chris@87: PyAPI_FUNC(PyObject*) _PyInt_Format(PyIntObject* v, int base, int newstyle); Chris@87: Chris@87: /* Format the object based on the format_spec, as defined in PEP 3101 Chris@87: (Advanced String Formatting). */ Chris@87: PyAPI_FUNC(PyObject *) _PyInt_FormatAdvanced(PyObject *obj, Chris@87: char *format_spec, Chris@87: Py_ssize_t format_spec_len); Chris@87: Chris@87: #ifdef __cplusplus Chris@87: } Chris@87: #endif Chris@87: #endif /* !Py_INTOBJECT_H */