intobject.h 2.67 KB
Newer Older
1

Guido van Rossum's avatar
Guido van Rossum committed
2 3 4
/* Integer object interface */

/*
5
PyIntObject represents a (long) integer.  This is an immutable object;
Guido van Rossum's avatar
Guido van Rossum committed
6 7 8 9
an integer cannot change its value after creation.

There are functions to create new integer objects, to test an object
for integer-ness, and to get the integer value.  The latter functions
10
returns -1 and sets errno to EBADF if the object is not an PyIntObject.
Guido van Rossum's avatar
Guido van Rossum committed
11 12
None of the functions should be applied to nil objects.

13
The type PyIntObject is (unfortunately) exposed here so we can declare
14
_Py_TrueStruct and _Py_ZeroStruct in boolobject.h; don't use this.
Guido van Rossum's avatar
Guido van Rossum committed
15 16
*/

17 18 19 20 21 22
#ifndef Py_INTOBJECT_H
#define Py_INTOBJECT_H
#ifdef __cplusplus
extern "C" {
#endif

Guido van Rossum's avatar
Guido van Rossum committed
23
typedef struct {
24 25
    PyObject_HEAD
    long ob_ival;
26
} PyIntObject;
Guido van Rossum's avatar
Guido van Rossum committed
27

28
PyAPI_DATA(PyTypeObject) PyInt_Type;
Guido van Rossum's avatar
Guido van Rossum committed
29

30 31
#define PyInt_Check(op) \
		 PyType_FastSubclass((op)->ob_type, Py_TPFLAGS_INT_SUBCLASS)
32
#define PyInt_CheckExact(op) ((op)->ob_type == &PyInt_Type)
Guido van Rossum's avatar
Guido van Rossum committed
33

34
PyAPI_FUNC(PyObject *) PyInt_FromString(char*, char**, int);
35
#ifdef Py_USING_UNICODE
Martin v. Löwis's avatar
Martin v. Löwis committed
36
PyAPI_FUNC(PyObject *) PyInt_FromUnicode(Py_UNICODE*, Py_ssize_t, int);
37
#endif
38
PyAPI_FUNC(PyObject *) PyInt_FromLong(long);
Martin v. Löwis's avatar
Martin v. Löwis committed
39 40
PyAPI_FUNC(PyObject *) PyInt_FromSize_t(size_t);
PyAPI_FUNC(PyObject *) PyInt_FromSsize_t(Py_ssize_t);
41
PyAPI_FUNC(long) PyInt_AsLong(PyObject *);
Martin v. Löwis's avatar
Martin v. Löwis committed
42
PyAPI_FUNC(Py_ssize_t) PyInt_AsSsize_t(PyObject *);
43 44 45 46 47
PyAPI_FUNC(unsigned long) PyInt_AsUnsignedLongMask(PyObject *);
#ifdef HAVE_LONG_LONG
PyAPI_FUNC(unsigned PY_LONG_LONG) PyInt_AsUnsignedLongLongMask(PyObject *);
#endif

48
PyAPI_FUNC(long) PyInt_GetMax(void);
Guido van Rossum's avatar
Guido van Rossum committed
49 50

/* Macro, trading safety for speed */
51
#define PyInt_AS_LONG(op) (((PyIntObject *)(op))->ob_ival)
52

53
/* These aren't really part of the Int object, but they're handy; the protos
54
 * are necessary for systems that need the magic of PyAPI_FUNC and that want
55 56 57 58
 * to have stropmodule as a dynamically loaded module instead of building it
 * into the main Python shared library/DLL.  Guido thinks I'm weird for
 * building it this way.  :-)  [cjh]
 */
59 60
PyAPI_FUNC(unsigned long) PyOS_strtoul(char *, char **, int);
PyAPI_FUNC(long) PyOS_strtol(char *, char **, int);
61

Christian Heimes's avatar
Christian Heimes committed
62
/* free list api */
63
PyAPI_FUNC(int) PyInt_ClearFreeList(void);
Christian Heimes's avatar
Christian Heimes committed
64

65 66 67 68 69 70
/* Convert an integer to the given base.  Returns a string.
   If base is 2, 8 or 16, add the proper prefix '0b', '0o' or '0x'.
   If newstyle is zero, then use the pre-2.6 behavior of octal having
   a leading "0" */
PyAPI_FUNC(PyObject*) _PyInt_Format(PyIntObject* v, int base, int newstyle);

71 72 73 74 75 76
/* Format the object based on the format_spec, as defined in PEP 3101
   (Advanced String Formatting). */
PyAPI_FUNC(PyObject *) _PyInt_FormatAdvanced(PyObject *obj,
					     char *format_spec,
					     Py_ssize_t format_spec_len);

77 78 79 80
#ifdef __cplusplus
}
#endif
#endif /* !Py_INTOBJECT_H */