annotate cos/python/Include/longobject.h @ 104:ed230e947dc6

Added hexviewer
author windel
date Sun, 30 Dec 2012 22:31:55 +0100
parents 7f74363f4c82
children
rev   line source
27
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
1 #ifndef Py_LONGOBJECT_H
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
2 #define Py_LONGOBJECT_H
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
3
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
4 /* Long (arbitrary precision) integer object interface */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
5
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
6 typedef struct _longobject PyLongObject; /* Revealed in longintrepr.h */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
7
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
8 PyAPI_DATA(PyTypeObject) PyLong_Type;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
9
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
10 #define PyLong_Check(op) \
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
11 PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LONG_SUBCLASS)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
12 #define PyLong_CheckExact(op) (Py_TYPE(op) == &PyLong_Type)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
13
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
14 PyAPI_FUNC(PyObject *) PyLong_FromLong(long);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
15 PyAPI_FUNC(PyObject *) PyLong_FromUnsignedLong(unsigned long);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
16 PyAPI_FUNC(PyObject *) PyLong_FromSize_t(size_t);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
17 PyAPI_FUNC(PyObject *) PyLong_FromSsize_t(Py_ssize_t);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
18 PyAPI_FUNC(PyObject *) PyLong_FromDouble(double);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
19 PyAPI_FUNC(long) PyLong_AsLong(PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
20 PyAPI_FUNC(long) PyLong_AsLongAndOverflow(PyObject *, int *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
21 PyAPI_FUNC(Py_ssize_t) PyLong_AsSsize_t(PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
22 PyAPI_FUNC(size_t) PyLong_AsSize_t(PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
23 PyAPI_FUNC(unsigned long) PyLong_AsUnsignedLong(PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
24 PyAPI_FUNC(unsigned long) PyLong_AsUnsignedLongMask(PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
25 PyAPI_FUNC(PyObject *) PyLong_GetInfo(void);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
26
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
27 /* It may be useful in the future. I've added it in the PyInt -> PyLong
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
28 cleanup to keep the extra information. [CH] */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
29 #define PyLong_AS_LONG(op) PyLong_AsLong(op)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
30
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
31 /* Issue #1983: pid_t can be longer than a C long on some systems */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
32 #if !defined(SIZEOF_PID_T) || SIZEOF_PID_T == SIZEOF_INT
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
33 #define _Py_PARSE_PID "i"
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
34 #define PyLong_FromPid PyLong_FromLong
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
35 #define PyLong_AsPid PyLong_AsLong
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
36 #elif SIZEOF_PID_T == SIZEOF_LONG
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
37 #define _Py_PARSE_PID "l"
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
38 #define PyLong_FromPid PyLong_FromLong
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
39 #define PyLong_AsPid PyLong_AsLong
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
40 #elif defined(SIZEOF_LONG_LONG) && SIZEOF_PID_T == SIZEOF_LONG_LONG
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
41 #define _Py_PARSE_PID "L"
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
42 #define PyLong_FromPid PyLong_FromLongLong
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
43 #define PyLong_AsPid PyLong_AsLongLong
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
44 #else
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
45 #error "sizeof(pid_t) is neither sizeof(int), sizeof(long) or sizeof(long long)"
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
46 #endif /* SIZEOF_PID_T */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
47
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
48 /* Used by Python/mystrtoul.c. */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
49 #ifndef Py_LIMITED_API
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
50 PyAPI_DATA(unsigned char) _PyLong_DigitValue[256];
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
51 #endif
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
52
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
53 /* _PyLong_Frexp returns a double x and an exponent e such that the
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
54 true value is approximately equal to x * 2**e. e is >= 0. x is
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
55 0.0 if and only if the input is 0 (in which case, e and x are both
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
56 zeroes); otherwise, 0.5 <= abs(x) < 1.0. On overflow, which is
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
57 possible if the number of bits doesn't fit into a Py_ssize_t, sets
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
58 OverflowError and returns -1.0 for x, 0 for e. */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
59 #ifndef Py_LIMITED_API
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
60 PyAPI_FUNC(double) _PyLong_Frexp(PyLongObject *a, Py_ssize_t *e);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
61 #endif
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
62
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
63 PyAPI_FUNC(double) PyLong_AsDouble(PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
64 PyAPI_FUNC(PyObject *) PyLong_FromVoidPtr(void *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
65 PyAPI_FUNC(void *) PyLong_AsVoidPtr(PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
66
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
67 #ifdef HAVE_LONG_LONG
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
68 PyAPI_FUNC(PyObject *) PyLong_FromLongLong(PY_LONG_LONG);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
69 PyAPI_FUNC(PyObject *) PyLong_FromUnsignedLongLong(unsigned PY_LONG_LONG);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
70 PyAPI_FUNC(PY_LONG_LONG) PyLong_AsLongLong(PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
71 PyAPI_FUNC(unsigned PY_LONG_LONG) PyLong_AsUnsignedLongLong(PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
72 PyAPI_FUNC(unsigned PY_LONG_LONG) PyLong_AsUnsignedLongLongMask(PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
73 PyAPI_FUNC(PY_LONG_LONG) PyLong_AsLongLongAndOverflow(PyObject *, int *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
74 #endif /* HAVE_LONG_LONG */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
75
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
76 PyAPI_FUNC(PyObject *) PyLong_FromString(char *, char **, int);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
77 #ifndef Py_LIMITED_API
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
78 PyAPI_FUNC(PyObject *) PyLong_FromUnicode(Py_UNICODE*, Py_ssize_t, int);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
79 PyAPI_FUNC(PyObject *) PyLong_FromUnicodeObject(PyObject *u, int base);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
80 #endif
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
81
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
82 #ifndef Py_LIMITED_API
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
83 /* _PyLong_Sign. Return 0 if v is 0, -1 if v < 0, +1 if v > 0.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
84 v must not be NULL, and must be a normalized long.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
85 There are no error cases.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
86 */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
87 PyAPI_FUNC(int) _PyLong_Sign(PyObject *v);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
88
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
89
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
90 /* _PyLong_NumBits. Return the number of bits needed to represent the
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
91 absolute value of a long. For example, this returns 1 for 1 and -1, 2
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
92 for 2 and -2, and 2 for 3 and -3. It returns 0 for 0.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
93 v must not be NULL, and must be a normalized long.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
94 (size_t)-1 is returned and OverflowError set if the true result doesn't
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
95 fit in a size_t.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
96 */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
97 PyAPI_FUNC(size_t) _PyLong_NumBits(PyObject *v);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
98
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
99 /* _PyLong_DivmodNear. Given integers a and b, compute the nearest
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
100 integer q to the exact quotient a / b, rounding to the nearest even integer
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
101 in the case of a tie. Return (q, r), where r = a - q*b. The remainder r
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
102 will satisfy abs(r) <= abs(b)/2, with equality possible only if q is
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
103 even.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
104 */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
105 PyAPI_FUNC(PyObject *) _PyLong_DivmodNear(PyObject *, PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
106
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
107 /* _PyLong_FromByteArray: View the n unsigned bytes as a binary integer in
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
108 base 256, and return a Python long with the same numeric value.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
109 If n is 0, the integer is 0. Else:
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
110 If little_endian is 1/true, bytes[n-1] is the MSB and bytes[0] the LSB;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
111 else (little_endian is 0/false) bytes[0] is the MSB and bytes[n-1] the
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
112 LSB.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
113 If is_signed is 0/false, view the bytes as a non-negative integer.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
114 If is_signed is 1/true, view the bytes as a 2's-complement integer,
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
115 non-negative if bit 0x80 of the MSB is clear, negative if set.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
116 Error returns:
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
117 + Return NULL with the appropriate exception set if there's not
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
118 enough memory to create the Python long.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
119 */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
120 PyAPI_FUNC(PyObject *) _PyLong_FromByteArray(
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
121 const unsigned char* bytes, size_t n,
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
122 int little_endian, int is_signed);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
123
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
124 /* _PyLong_AsByteArray: Convert the least-significant 8*n bits of long
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
125 v to a base-256 integer, stored in array bytes. Normally return 0,
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
126 return -1 on error.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
127 If little_endian is 1/true, store the MSB at bytes[n-1] and the LSB at
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
128 bytes[0]; else (little_endian is 0/false) store the MSB at bytes[0] and
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
129 the LSB at bytes[n-1].
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
130 If is_signed is 0/false, it's an error if v < 0; else (v >= 0) n bytes
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
131 are filled and there's nothing special about bit 0x80 of the MSB.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
132 If is_signed is 1/true, bytes is filled with the 2's-complement
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
133 representation of v's value. Bit 0x80 of the MSB is the sign bit.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
134 Error returns (-1):
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
135 + is_signed is 0 and v < 0. TypeError is set in this case, and bytes
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
136 isn't altered.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
137 + n isn't big enough to hold the full mathematical value of v. For
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
138 example, if is_signed is 0 and there are more digits in the v than
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
139 fit in n; or if is_signed is 1, v < 0, and n is just 1 bit shy of
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
140 being large enough to hold a sign bit. OverflowError is set in this
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
141 case, but bytes holds the least-signficant n bytes of the true value.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
142 */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
143 PyAPI_FUNC(int) _PyLong_AsByteArray(PyLongObject* v,
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
144 unsigned char* bytes, size_t n,
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
145 int little_endian, int is_signed);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
146
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
147
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
148 /* _PyLong_Format: Convert the long to a string object with given base,
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
149 appending a base prefix of 0[box] if base is 2, 8 or 16. */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
150 PyAPI_FUNC(PyObject *) _PyLong_Format(PyObject *aa, int base);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
151
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
152 /* Format the object based on the format_spec, as defined in PEP 3101
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
153 (Advanced String Formatting). */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
154 PyAPI_FUNC(PyObject *) _PyLong_FormatAdvanced(PyObject *obj,
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
155 PyObject *format_spec,
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
156 Py_ssize_t start,
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
157 Py_ssize_t end);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
158 #endif /* Py_LIMITED_API */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
159
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
160 /* These aren't really part of the long object, but they're handy. The
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
161 functions are in Python/mystrtoul.c.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
162 */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
163 PyAPI_FUNC(unsigned long) PyOS_strtoul(char *, char **, int);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
164 PyAPI_FUNC(long) PyOS_strtol(char *, char **, int);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
165
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
166 #endif /* !Py_LONGOBJECT_H */