annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/include/python3.8/longobject.h @ 69:33d812a61356

planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author jpayne
date Tue, 18 Mar 2025 17:55:14 -0400
parents
children
rev   line source
jpayne@69 1 #ifndef Py_LONGOBJECT_H
jpayne@69 2 #define Py_LONGOBJECT_H
jpayne@69 3 #ifdef __cplusplus
jpayne@69 4 extern "C" {
jpayne@69 5 #endif
jpayne@69 6
jpayne@69 7
jpayne@69 8 /* Long (arbitrary precision) integer object interface */
jpayne@69 9
jpayne@69 10 typedef struct _longobject PyLongObject; /* Revealed in longintrepr.h */
jpayne@69 11
jpayne@69 12 PyAPI_DATA(PyTypeObject) PyLong_Type;
jpayne@69 13
jpayne@69 14 #define PyLong_Check(op) \
jpayne@69 15 PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LONG_SUBCLASS)
jpayne@69 16 #define PyLong_CheckExact(op) (Py_TYPE(op) == &PyLong_Type)
jpayne@69 17
jpayne@69 18 PyAPI_FUNC(PyObject *) PyLong_FromLong(long);
jpayne@69 19 PyAPI_FUNC(PyObject *) PyLong_FromUnsignedLong(unsigned long);
jpayne@69 20 PyAPI_FUNC(PyObject *) PyLong_FromSize_t(size_t);
jpayne@69 21 PyAPI_FUNC(PyObject *) PyLong_FromSsize_t(Py_ssize_t);
jpayne@69 22 PyAPI_FUNC(PyObject *) PyLong_FromDouble(double);
jpayne@69 23 PyAPI_FUNC(long) PyLong_AsLong(PyObject *);
jpayne@69 24 PyAPI_FUNC(long) PyLong_AsLongAndOverflow(PyObject *, int *);
jpayne@69 25 PyAPI_FUNC(Py_ssize_t) PyLong_AsSsize_t(PyObject *);
jpayne@69 26 PyAPI_FUNC(size_t) PyLong_AsSize_t(PyObject *);
jpayne@69 27 PyAPI_FUNC(unsigned long) PyLong_AsUnsignedLong(PyObject *);
jpayne@69 28 PyAPI_FUNC(unsigned long) PyLong_AsUnsignedLongMask(PyObject *);
jpayne@69 29 #ifndef Py_LIMITED_API
jpayne@69 30 PyAPI_FUNC(int) _PyLong_AsInt(PyObject *);
jpayne@69 31 #endif
jpayne@69 32 PyAPI_FUNC(PyObject *) PyLong_GetInfo(void);
jpayne@69 33
jpayne@69 34 /* It may be useful in the future. I've added it in the PyInt -> PyLong
jpayne@69 35 cleanup to keep the extra information. [CH] */
jpayne@69 36 #define PyLong_AS_LONG(op) PyLong_AsLong(op)
jpayne@69 37
jpayne@69 38 /* Issue #1983: pid_t can be longer than a C long on some systems */
jpayne@69 39 #if !defined(SIZEOF_PID_T) || SIZEOF_PID_T == SIZEOF_INT
jpayne@69 40 #define _Py_PARSE_PID "i"
jpayne@69 41 #define PyLong_FromPid PyLong_FromLong
jpayne@69 42 #define PyLong_AsPid PyLong_AsLong
jpayne@69 43 #elif SIZEOF_PID_T == SIZEOF_LONG
jpayne@69 44 #define _Py_PARSE_PID "l"
jpayne@69 45 #define PyLong_FromPid PyLong_FromLong
jpayne@69 46 #define PyLong_AsPid PyLong_AsLong
jpayne@69 47 #elif defined(SIZEOF_LONG_LONG) && SIZEOF_PID_T == SIZEOF_LONG_LONG
jpayne@69 48 #define _Py_PARSE_PID "L"
jpayne@69 49 #define PyLong_FromPid PyLong_FromLongLong
jpayne@69 50 #define PyLong_AsPid PyLong_AsLongLong
jpayne@69 51 #else
jpayne@69 52 #error "sizeof(pid_t) is neither sizeof(int), sizeof(long) or sizeof(long long)"
jpayne@69 53 #endif /* SIZEOF_PID_T */
jpayne@69 54
jpayne@69 55 #if SIZEOF_VOID_P == SIZEOF_INT
jpayne@69 56 # define _Py_PARSE_INTPTR "i"
jpayne@69 57 # define _Py_PARSE_UINTPTR "I"
jpayne@69 58 #elif SIZEOF_VOID_P == SIZEOF_LONG
jpayne@69 59 # define _Py_PARSE_INTPTR "l"
jpayne@69 60 # define _Py_PARSE_UINTPTR "k"
jpayne@69 61 #elif defined(SIZEOF_LONG_LONG) && SIZEOF_VOID_P == SIZEOF_LONG_LONG
jpayne@69 62 # define _Py_PARSE_INTPTR "L"
jpayne@69 63 # define _Py_PARSE_UINTPTR "K"
jpayne@69 64 #else
jpayne@69 65 # error "void* different in size from int, long and long long"
jpayne@69 66 #endif /* SIZEOF_VOID_P */
jpayne@69 67
jpayne@69 68 #ifndef Py_LIMITED_API
jpayne@69 69 PyAPI_FUNC(int) _PyLong_UnsignedShort_Converter(PyObject *, void *);
jpayne@69 70 PyAPI_FUNC(int) _PyLong_UnsignedInt_Converter(PyObject *, void *);
jpayne@69 71 PyAPI_FUNC(int) _PyLong_UnsignedLong_Converter(PyObject *, void *);
jpayne@69 72 PyAPI_FUNC(int) _PyLong_UnsignedLongLong_Converter(PyObject *, void *);
jpayne@69 73 PyAPI_FUNC(int) _PyLong_Size_t_Converter(PyObject *, void *);
jpayne@69 74 #endif
jpayne@69 75
jpayne@69 76 /* Used by Python/mystrtoul.c, _PyBytes_FromHex(),
jpayne@69 77 _PyBytes_DecodeEscapeRecode(), etc. */
jpayne@69 78 #ifndef Py_LIMITED_API
jpayne@69 79 PyAPI_DATA(unsigned char) _PyLong_DigitValue[256];
jpayne@69 80 #endif
jpayne@69 81
jpayne@69 82 /* _PyLong_Frexp returns a double x and an exponent e such that the
jpayne@69 83 true value is approximately equal to x * 2**e. e is >= 0. x is
jpayne@69 84 0.0 if and only if the input is 0 (in which case, e and x are both
jpayne@69 85 zeroes); otherwise, 0.5 <= abs(x) < 1.0. On overflow, which is
jpayne@69 86 possible if the number of bits doesn't fit into a Py_ssize_t, sets
jpayne@69 87 OverflowError and returns -1.0 for x, 0 for e. */
jpayne@69 88 #ifndef Py_LIMITED_API
jpayne@69 89 PyAPI_FUNC(double) _PyLong_Frexp(PyLongObject *a, Py_ssize_t *e);
jpayne@69 90 #endif
jpayne@69 91
jpayne@69 92 PyAPI_FUNC(double) PyLong_AsDouble(PyObject *);
jpayne@69 93 PyAPI_FUNC(PyObject *) PyLong_FromVoidPtr(void *);
jpayne@69 94 PyAPI_FUNC(void *) PyLong_AsVoidPtr(PyObject *);
jpayne@69 95
jpayne@69 96 PyAPI_FUNC(PyObject *) PyLong_FromLongLong(long long);
jpayne@69 97 PyAPI_FUNC(PyObject *) PyLong_FromUnsignedLongLong(unsigned long long);
jpayne@69 98 PyAPI_FUNC(long long) PyLong_AsLongLong(PyObject *);
jpayne@69 99 PyAPI_FUNC(unsigned long long) PyLong_AsUnsignedLongLong(PyObject *);
jpayne@69 100 PyAPI_FUNC(unsigned long long) PyLong_AsUnsignedLongLongMask(PyObject *);
jpayne@69 101 PyAPI_FUNC(long long) PyLong_AsLongLongAndOverflow(PyObject *, int *);
jpayne@69 102
jpayne@69 103 PyAPI_FUNC(PyObject *) PyLong_FromString(const char *, char **, int);
jpayne@69 104 #ifndef Py_LIMITED_API
jpayne@69 105 Py_DEPRECATED(3.3)
jpayne@69 106 PyAPI_FUNC(PyObject *) PyLong_FromUnicode(Py_UNICODE*, Py_ssize_t, int);
jpayne@69 107 PyAPI_FUNC(PyObject *) PyLong_FromUnicodeObject(PyObject *u, int base);
jpayne@69 108 PyAPI_FUNC(PyObject *) _PyLong_FromBytes(const char *, Py_ssize_t, int);
jpayne@69 109 #endif
jpayne@69 110
jpayne@69 111 #ifndef Py_LIMITED_API
jpayne@69 112 /* _PyLong_Sign. Return 0 if v is 0, -1 if v < 0, +1 if v > 0.
jpayne@69 113 v must not be NULL, and must be a normalized long.
jpayne@69 114 There are no error cases.
jpayne@69 115 */
jpayne@69 116 PyAPI_FUNC(int) _PyLong_Sign(PyObject *v);
jpayne@69 117
jpayne@69 118
jpayne@69 119 /* _PyLong_NumBits. Return the number of bits needed to represent the
jpayne@69 120 absolute value of a long. For example, this returns 1 for 1 and -1, 2
jpayne@69 121 for 2 and -2, and 2 for 3 and -3. It returns 0 for 0.
jpayne@69 122 v must not be NULL, and must be a normalized long.
jpayne@69 123 (size_t)-1 is returned and OverflowError set if the true result doesn't
jpayne@69 124 fit in a size_t.
jpayne@69 125 */
jpayne@69 126 PyAPI_FUNC(size_t) _PyLong_NumBits(PyObject *v);
jpayne@69 127
jpayne@69 128 /* _PyLong_DivmodNear. Given integers a and b, compute the nearest
jpayne@69 129 integer q to the exact quotient a / b, rounding to the nearest even integer
jpayne@69 130 in the case of a tie. Return (q, r), where r = a - q*b. The remainder r
jpayne@69 131 will satisfy abs(r) <= abs(b)/2, with equality possible only if q is
jpayne@69 132 even.
jpayne@69 133 */
jpayne@69 134 PyAPI_FUNC(PyObject *) _PyLong_DivmodNear(PyObject *, PyObject *);
jpayne@69 135
jpayne@69 136 /* _PyLong_FromByteArray: View the n unsigned bytes as a binary integer in
jpayne@69 137 base 256, and return a Python int with the same numeric value.
jpayne@69 138 If n is 0, the integer is 0. Else:
jpayne@69 139 If little_endian is 1/true, bytes[n-1] is the MSB and bytes[0] the LSB;
jpayne@69 140 else (little_endian is 0/false) bytes[0] is the MSB and bytes[n-1] the
jpayne@69 141 LSB.
jpayne@69 142 If is_signed is 0/false, view the bytes as a non-negative integer.
jpayne@69 143 If is_signed is 1/true, view the bytes as a 2's-complement integer,
jpayne@69 144 non-negative if bit 0x80 of the MSB is clear, negative if set.
jpayne@69 145 Error returns:
jpayne@69 146 + Return NULL with the appropriate exception set if there's not
jpayne@69 147 enough memory to create the Python int.
jpayne@69 148 */
jpayne@69 149 PyAPI_FUNC(PyObject *) _PyLong_FromByteArray(
jpayne@69 150 const unsigned char* bytes, size_t n,
jpayne@69 151 int little_endian, int is_signed);
jpayne@69 152
jpayne@69 153 /* _PyLong_AsByteArray: Convert the least-significant 8*n bits of long
jpayne@69 154 v to a base-256 integer, stored in array bytes. Normally return 0,
jpayne@69 155 return -1 on error.
jpayne@69 156 If little_endian is 1/true, store the MSB at bytes[n-1] and the LSB at
jpayne@69 157 bytes[0]; else (little_endian is 0/false) store the MSB at bytes[0] and
jpayne@69 158 the LSB at bytes[n-1].
jpayne@69 159 If is_signed is 0/false, it's an error if v < 0; else (v >= 0) n bytes
jpayne@69 160 are filled and there's nothing special about bit 0x80 of the MSB.
jpayne@69 161 If is_signed is 1/true, bytes is filled with the 2's-complement
jpayne@69 162 representation of v's value. Bit 0x80 of the MSB is the sign bit.
jpayne@69 163 Error returns (-1):
jpayne@69 164 + is_signed is 0 and v < 0. TypeError is set in this case, and bytes
jpayne@69 165 isn't altered.
jpayne@69 166 + n isn't big enough to hold the full mathematical value of v. For
jpayne@69 167 example, if is_signed is 0 and there are more digits in the v than
jpayne@69 168 fit in n; or if is_signed is 1, v < 0, and n is just 1 bit shy of
jpayne@69 169 being large enough to hold a sign bit. OverflowError is set in this
jpayne@69 170 case, but bytes holds the least-significant n bytes of the true value.
jpayne@69 171 */
jpayne@69 172 PyAPI_FUNC(int) _PyLong_AsByteArray(PyLongObject* v,
jpayne@69 173 unsigned char* bytes, size_t n,
jpayne@69 174 int little_endian, int is_signed);
jpayne@69 175
jpayne@69 176 /* _PyLong_FromNbInt: Convert the given object to a PyLongObject
jpayne@69 177 using the nb_int slot, if available. Raise TypeError if either the
jpayne@69 178 nb_int slot is not available or the result of the call to nb_int
jpayne@69 179 returns something not of type int.
jpayne@69 180 */
jpayne@69 181 PyAPI_FUNC(PyObject *) _PyLong_FromNbInt(PyObject *);
jpayne@69 182
jpayne@69 183 /* Convert the given object to a PyLongObject using the nb_index or
jpayne@69 184 nb_int slots, if available (the latter is deprecated).
jpayne@69 185 Raise TypeError if either nb_index and nb_int slots are not
jpayne@69 186 available or the result of the call to nb_index or nb_int
jpayne@69 187 returns something not of type int.
jpayne@69 188 Should be replaced with PyNumber_Index after the end of the
jpayne@69 189 deprecation period.
jpayne@69 190 */
jpayne@69 191 PyAPI_FUNC(PyObject *) _PyLong_FromNbIndexOrNbInt(PyObject *);
jpayne@69 192
jpayne@69 193 /* _PyLong_Format: Convert the long to a string object with given base,
jpayne@69 194 appending a base prefix of 0[box] if base is 2, 8 or 16. */
jpayne@69 195 PyAPI_FUNC(PyObject *) _PyLong_Format(PyObject *obj, int base);
jpayne@69 196
jpayne@69 197 PyAPI_FUNC(int) _PyLong_FormatWriter(
jpayne@69 198 _PyUnicodeWriter *writer,
jpayne@69 199 PyObject *obj,
jpayne@69 200 int base,
jpayne@69 201 int alternate);
jpayne@69 202
jpayne@69 203 PyAPI_FUNC(char*) _PyLong_FormatBytesWriter(
jpayne@69 204 _PyBytesWriter *writer,
jpayne@69 205 char *str,
jpayne@69 206 PyObject *obj,
jpayne@69 207 int base,
jpayne@69 208 int alternate);
jpayne@69 209
jpayne@69 210 /* Format the object based on the format_spec, as defined in PEP 3101
jpayne@69 211 (Advanced String Formatting). */
jpayne@69 212 PyAPI_FUNC(int) _PyLong_FormatAdvancedWriter(
jpayne@69 213 _PyUnicodeWriter *writer,
jpayne@69 214 PyObject *obj,
jpayne@69 215 PyObject *format_spec,
jpayne@69 216 Py_ssize_t start,
jpayne@69 217 Py_ssize_t end);
jpayne@69 218 #endif /* Py_LIMITED_API */
jpayne@69 219
jpayne@69 220 /* These aren't really part of the int object, but they're handy. The
jpayne@69 221 functions are in Python/mystrtoul.c.
jpayne@69 222 */
jpayne@69 223 PyAPI_FUNC(unsigned long) PyOS_strtoul(const char *, char **, int);
jpayne@69 224 PyAPI_FUNC(long) PyOS_strtol(const char *, char **, int);
jpayne@69 225
jpayne@69 226 #ifndef Py_LIMITED_API
jpayne@69 227 /* For use by the gcd function in mathmodule.c */
jpayne@69 228 PyAPI_FUNC(PyObject *) _PyLong_GCD(PyObject *, PyObject *);
jpayne@69 229 #endif /* !Py_LIMITED_API */
jpayne@69 230
jpayne@69 231 #ifndef Py_LIMITED_API
jpayne@69 232 PyAPI_DATA(PyObject *) _PyLong_Zero;
jpayne@69 233 PyAPI_DATA(PyObject *) _PyLong_One;
jpayne@69 234
jpayne@69 235 PyAPI_FUNC(PyObject *) _PyLong_Rshift(PyObject *, size_t);
jpayne@69 236 PyAPI_FUNC(PyObject *) _PyLong_Lshift(PyObject *, size_t);
jpayne@69 237 #endif
jpayne@69 238
jpayne@69 239 #ifdef __cplusplus
jpayne@69 240 }
jpayne@69 241 #endif
jpayne@69 242 #endif /* !Py_LONGOBJECT_H */