1 /**
2   Mirror _intobject.h
3 
4 Integer object interface 
5 
6 PyIntObject represents a (long) integer.  This is an immutable object;
7 an integer cannot change its value after creation.
8 
9 There are functions to create new integer objects, to test an object
10 for integer-ness, and to get the integer value.  The latter functions
11 returns -1 and sets errno to EBADF if the object is not an PyIntObject.
12 None of the functions should be applied to nil objects.
13 
14 The type PyIntObject is (unfortunately) exposed here so we can declare
15 _Py_TrueStruct and _Py_ZeroStruct in boolobject.h; don't use this.
16 
17   Note _intobject has gone away in favor of longobject in python 3.
18   */
19 module deimos.python.intobject;
20 
21 import deimos.python.pyport;
22 import deimos.python.object;
23 import deimos.python.unicodeobject;
24 
25 version(Python_3_0_Or_Later) {
26     // int merged with long in python 3
27 }else {
28 extern(C):
29 // Python-header-file: Include/intobject.h:
30 
31 /// subclass of PyObject
32 /// Availability: 2.*
33 struct PyIntObject {
34     mixin PyObject_HEAD;
35 
36     /// _
37     C_long ob_ival;
38 }
39 
40 /// Availability: 2.*
41 mixin(PyAPI_DATA!"PyTypeObject PyInt_Type");
42 
43 // D translation of C macro:
44 /// Availability: 2.*
45 int PyInt_Check()(PyObject* op) {
46     return PyObject_TypeCheck(op, &PyInt_Type);
47 }
48 // D translation of C macro:
49 /// Availability: 2.*
50 int PyInt_CheckExact()(PyObject* op) {
51     return op.ob_type == &PyInt_Type;
52 }
53 
54 /// Availability: 2.*
55 PyObject* PyInt_FromString(char*, char**, int);
56 /// Availability: 2.*
57 PyObject* PyInt_FromUnicode(Py_UNICODE*, Py_ssize_t, int);
58 /// Availability: 2.*
59 PyObject* PyInt_FromLong(C_long);
60 version(Python_2_5_Or_Later){
61     /// Availability: 2.5, 2.6, 2.7
62     PyObject* PyInt_FromSize_t(size_t);
63     /// Availability: 2.5, 2.6, 2.7
64     PyObject* PyInt_FromSsize_t(Py_ssize_t);
65 
66     /// Availability: 2.5, 2.6, 2.7
67     Py_ssize_t PyInt_AsSsize_t(PyObject*);
68 }
69 
70 /// Availability: 2.*
71 C_long PyInt_AsLong(PyObject*);
72 /// Availability: 2.*
73 C_ulong PyInt_AsUnsignedLongMask(PyObject*);
74 /// Availability: 2.*
75 C_ulonglong PyInt_AsUnsignedLongLongMask(PyObject*);
76 
77 /** Accessible at the Python level as sys.maxint */
78 C_long PyInt_GetMax(); 
79 
80 /// Availability: 2.*
81 C_ulong PyOS_strtoul(char*, char**, int);
82 /// Availability: 2.*
83 C_long PyOS_strtol(char*, char**, int);
84 version(Python_2_6_Or_Later){
85     /// Availability: >= 2.6
86     C_long PyOS_strtol(char*, char**, int);
87 
88     /** free list api */
89     /// Availability: >= 2.6
90     int PyInt_ClearFreeList();
91 
92     /** Convert an integer to the given base.  Returns a string.
93        If base is 2, 8 or 16, add the proper prefix '0b', '0o' or '0x'.
94        If newstyle is zero, then use the pre-2.6 behavior of octal having
95        a leading "0" */
96     /// Availability: >= 2.6
97     PyObject* _PyInt_Format(PyIntObject* v, int base, int newstyle);
98 
99     /** Format the object based on the format_spec, as defined in PEP 3101
100        (Advanced String Formatting). */
101     /// Availability: >= 2.6
102     PyObject*  _PyInt_FormatAdvanced(PyObject* obj,
103             char* format_spec,
104             Py_ssize_t format_spec_len);
105 }
106 
107 
108 }