Mercurial > cpython-lru_cache-weakref
annotate Include/longobject.h @ 70817:dd775b1561ba
Fix markup.
| author | Georg Brandl <georg@python.org> |
|---|---|
| date | Tue, 14 Jun 2011 21:09:55 +0200 |
| parents | 3c9232a684ae |
| children | 974ace29ee2d 8beaa9a37387 |
| rev | line source |
|---|---|
|
1329
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
1 #ifndef Py_LONGOBJECT_H |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
2 #define Py_LONGOBJECT_H |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
3 #ifdef __cplusplus |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
4 extern "C" { |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
5 #endif |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
6 |
| 230 | 7 |
| 8 /* Long (arbitrary precision) integer object interface */ | |
| 9 | |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2058
diff
changeset
|
10 typedef struct _longobject PyLongObject; /* Revealed in longintrepr.h */ |
|
614
11e86270ed0d
Added typedef for longobject and declarations for long_{format,scan}.
Guido van Rossum <guido@python.org>
parents:
255
diff
changeset
|
11 |
|
24752
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24210
diff
changeset
|
12 PyAPI_DATA(PyTypeObject) PyLong_Type; |
| 230 | 13 |
|
40909
f2f0b41f270d
Merged revisions 53875-53911 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40626
diff
changeset
|
14 #define PyLong_Check(op) \ |
|
44351
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44160
diff
changeset
|
15 PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LONG_SUBCLASS) |
|
86a2679dca46
#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents:
44160
diff
changeset
|
16 #define PyLong_CheckExact(op) (Py_TYPE(op) == &PyLong_Type) |
| 230 | 17 |
|
24752
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24210
diff
changeset
|
18 PyAPI_FUNC(PyObject *) PyLong_FromLong(long); |
|
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24210
diff
changeset
|
19 PyAPI_FUNC(PyObject *) PyLong_FromUnsignedLong(unsigned long); |
|
40626
4aee3f672f77
Merged the int/long unification branch, by very crude means (sorry Thomas!).
Guido van Rossum <guido@python.org>
parents:
38453
diff
changeset
|
20 PyAPI_FUNC(PyObject *) PyLong_FromSize_t(size_t); |
|
4aee3f672f77
Merged the int/long unification branch, by very crude means (sorry Thomas!).
Guido van Rossum <guido@python.org>
parents:
38453
diff
changeset
|
21 PyAPI_FUNC(PyObject *) PyLong_FromSsize_t(Py_ssize_t); |
|
24752
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24210
diff
changeset
|
22 PyAPI_FUNC(PyObject *) PyLong_FromDouble(double); |
|
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24210
diff
changeset
|
23 PyAPI_FUNC(long) PyLong_AsLong(PyObject *); |
|
44158
81e0c0e2a8c1
Remove PyInt_CheckExact. Add PyLong_AsLongAndOverflow.
Martin v. Löwis <martin@v.loewis.de>
parents:
44107
diff
changeset
|
24 PyAPI_FUNC(long) PyLong_AsLongAndOverflow(PyObject *, int *); |
|
40966
140f3524027f
I assume this was supposed to be Py_ssize_t since there are no uses of plain ssize_t.
Neal Norwitz <nnorwitz@gmail.com>
parents:
40909
diff
changeset
|
25 PyAPI_FUNC(Py_ssize_t) PyLong_AsSsize_t(PyObject *); |
|
40626
4aee3f672f77
Merged the int/long unification branch, by very crude means (sorry Thomas!).
Guido van Rossum <guido@python.org>
parents:
38453
diff
changeset
|
26 PyAPI_FUNC(size_t) PyLong_AsSize_t(PyObject *); |
|
24752
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24210
diff
changeset
|
27 PyAPI_FUNC(unsigned long) PyLong_AsUnsignedLong(PyObject *); |
|
28652
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
28 PyAPI_FUNC(unsigned long) PyLong_AsUnsignedLongMask(PyObject *); |
|
52215
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
50656
diff
changeset
|
29 PyAPI_FUNC(PyObject *) PyLong_GetInfo(void); |
|
19671
7df300d284c6
Introduce new private API function _PyLong_AsScaledDouble. Not used yet,
Tim Peters <tim.peters@gmail.com>
parents:
19550
diff
changeset
|
30 |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
43881
diff
changeset
|
31 /* It may be useful in the future. I've added it in the PyInt -> PyLong |
|
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
43881
diff
changeset
|
32 cleanup to keep the extra information. [CH] */ |
|
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
43881
diff
changeset
|
33 #define PyLong_AS_LONG(op) PyLong_AsLong(op) |
|
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
43881
diff
changeset
|
34 |
|
59605
768722b2ae0a
* Replaces the internals of the subprocess module from fork through exec on
Gregory P. Smith <greg@mad-scientist.com>
parents:
58582
diff
changeset
|
35 /* Issue #1983: pid_t can be longer than a C long on some systems */ |
|
768722b2ae0a
* Replaces the internals of the subprocess module from fork through exec on
Gregory P. Smith <greg@mad-scientist.com>
parents:
58582
diff
changeset
|
36 #if !defined(SIZEOF_PID_T) || SIZEOF_PID_T == SIZEOF_INT |
|
59625
8f1993b866f7
Change PARSE_PID to _Py_PARSE_PID (cleanup for r78946).
Gregory P. Smith <greg@mad-scientist.com>
parents:
59605
diff
changeset
|
37 #define _Py_PARSE_PID "i" |
|
59605
768722b2ae0a
* Replaces the internals of the subprocess module from fork through exec on
Gregory P. Smith <greg@mad-scientist.com>
parents:
58582
diff
changeset
|
38 #define PyLong_FromPid PyLong_FromLong |
|
768722b2ae0a
* Replaces the internals of the subprocess module from fork through exec on
Gregory P. Smith <greg@mad-scientist.com>
parents:
58582
diff
changeset
|
39 #define PyLong_AsPid PyLong_AsLong |
|
768722b2ae0a
* Replaces the internals of the subprocess module from fork through exec on
Gregory P. Smith <greg@mad-scientist.com>
parents:
58582
diff
changeset
|
40 #elif SIZEOF_PID_T == SIZEOF_LONG |
|
59625
8f1993b866f7
Change PARSE_PID to _Py_PARSE_PID (cleanup for r78946).
Gregory P. Smith <greg@mad-scientist.com>
parents:
59605
diff
changeset
|
41 #define _Py_PARSE_PID "l" |
|
59605
768722b2ae0a
* Replaces the internals of the subprocess module from fork through exec on
Gregory P. Smith <greg@mad-scientist.com>
parents:
58582
diff
changeset
|
42 #define PyLong_FromPid PyLong_FromLong |
|
768722b2ae0a
* Replaces the internals of the subprocess module from fork through exec on
Gregory P. Smith <greg@mad-scientist.com>
parents:
58582
diff
changeset
|
43 #define PyLong_AsPid PyLong_AsLong |
|
768722b2ae0a
* Replaces the internals of the subprocess module from fork through exec on
Gregory P. Smith <greg@mad-scientist.com>
parents:
58582
diff
changeset
|
44 #elif defined(SIZEOF_LONG_LONG) && SIZEOF_PID_T == SIZEOF_LONG_LONG |
|
59625
8f1993b866f7
Change PARSE_PID to _Py_PARSE_PID (cleanup for r78946).
Gregory P. Smith <greg@mad-scientist.com>
parents:
59605
diff
changeset
|
45 #define _Py_PARSE_PID "L" |
|
59605
768722b2ae0a
* Replaces the internals of the subprocess module from fork through exec on
Gregory P. Smith <greg@mad-scientist.com>
parents:
58582
diff
changeset
|
46 #define PyLong_FromPid PyLong_FromLongLong |
|
768722b2ae0a
* Replaces the internals of the subprocess module from fork through exec on
Gregory P. Smith <greg@mad-scientist.com>
parents:
58582
diff
changeset
|
47 #define PyLong_AsPid PyLong_AsLongLong |
|
768722b2ae0a
* Replaces the internals of the subprocess module from fork through exec on
Gregory P. Smith <greg@mad-scientist.com>
parents:
58582
diff
changeset
|
48 #else |
|
768722b2ae0a
* Replaces the internals of the subprocess module from fork through exec on
Gregory P. Smith <greg@mad-scientist.com>
parents:
58582
diff
changeset
|
49 #error "sizeof(pid_t) is neither sizeof(int), sizeof(long) or sizeof(long long)" |
|
768722b2ae0a
* Replaces the internals of the subprocess module from fork through exec on
Gregory P. Smith <greg@mad-scientist.com>
parents:
58582
diff
changeset
|
50 #endif /* SIZEOF_PID_T */ |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
33540
diff
changeset
|
51 |
|
62558
ec0fd5a6bb45
Issue #9089: Remove references to intobject.c and intobject.h from comments.
Mark Dickinson <dickinsm@gmail.com>
parents:
62154
diff
changeset
|
52 /* Used by Python/mystrtoul.c. */ |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
64301
diff
changeset
|
53 #ifndef Py_LIMITED_API |
|
50656
c7c344b63ecc
Reduce the size of the _PyLong_DigitValue table.
Raymond Hettinger <python@rcn.com>
parents:
47393
diff
changeset
|
54 PyAPI_DATA(unsigned char) _PyLong_DigitValue[256]; |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
64301
diff
changeset
|
55 #endif |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
33540
diff
changeset
|
56 |
|
58088
46d60e5ff103
Merged revisions 77234 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
52215
diff
changeset
|
57 /* _PyLong_Frexp returns a double x and an exponent e such that the |
|
46d60e5ff103
Merged revisions 77234 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
52215
diff
changeset
|
58 true value is approximately equal to x * 2**e. e is >= 0. x is |
|
46d60e5ff103
Merged revisions 77234 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
52215
diff
changeset
|
59 0.0 if and only if the input is 0 (in which case, e and x are both |
|
46d60e5ff103
Merged revisions 77234 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
52215
diff
changeset
|
60 zeroes); otherwise, 0.5 <= abs(x) < 1.0. On overflow, which is |
|
46d60e5ff103
Merged revisions 77234 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
52215
diff
changeset
|
61 possible if the number of bits doesn't fit into a Py_ssize_t, sets |
|
46d60e5ff103
Merged revisions 77234 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
52215
diff
changeset
|
62 OverflowError and returns -1.0 for x, 0 for e. */ |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
64301
diff
changeset
|
63 #ifndef Py_LIMITED_API |
|
58088
46d60e5ff103
Merged revisions 77234 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
52215
diff
changeset
|
64 PyAPI_FUNC(double) _PyLong_Frexp(PyLongObject *a, Py_ssize_t *e); |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
64301
diff
changeset
|
65 #endif |
|
19671
7df300d284c6
Introduce new private API function _PyLong_AsScaledDouble. Not used yet,
Tim Peters <tim.peters@gmail.com>
parents:
19550
diff
changeset
|
66 |
|
24752
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24210
diff
changeset
|
67 PyAPI_FUNC(double) PyLong_AsDouble(PyObject *); |
|
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24210
diff
changeset
|
68 PyAPI_FUNC(PyObject *) PyLong_FromVoidPtr(void *); |
|
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24210
diff
changeset
|
69 PyAPI_FUNC(void *) PyLong_AsVoidPtr(PyObject *); |
|
614
11e86270ed0d
Added typedef for longobject and declarations for long_{format,scan}.
Guido van Rossum <guido@python.org>
parents:
255
diff
changeset
|
70 |
|
8822
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
4870
diff
changeset
|
71 #ifdef HAVE_LONG_LONG |
|
28437
871da703e4c0
Rename LONG_LONG to PY_LONG_LONG. Fixes #710285.
Martin v. Löwis <martin@v.loewis.de>
parents:
27549
diff
changeset
|
72 PyAPI_FUNC(PyObject *) PyLong_FromLongLong(PY_LONG_LONG); |
|
871da703e4c0
Rename LONG_LONG to PY_LONG_LONG. Fixes #710285.
Martin v. Löwis <martin@v.loewis.de>
parents:
27549
diff
changeset
|
73 PyAPI_FUNC(PyObject *) PyLong_FromUnsignedLongLong(unsigned PY_LONG_LONG); |
|
871da703e4c0
Rename LONG_LONG to PY_LONG_LONG. Fixes #710285.
Martin v. Löwis <martin@v.loewis.de>
parents:
27549
diff
changeset
|
74 PyAPI_FUNC(PY_LONG_LONG) PyLong_AsLongLong(PyObject *); |
|
871da703e4c0
Rename LONG_LONG to PY_LONG_LONG. Fixes #710285.
Martin v. Löwis <martin@v.loewis.de>
parents:
27549
diff
changeset
|
75 PyAPI_FUNC(unsigned PY_LONG_LONG) PyLong_AsUnsignedLongLong(PyObject *); |
|
28652
28a2975514cd
SF # 595026: support for masks in getargs.c.
Thomas Heller <theller@ctypes.org>
parents:
28437
diff
changeset
|
76 PyAPI_FUNC(unsigned PY_LONG_LONG) PyLong_AsUnsignedLongLongMask(PyObject *); |
|
58582
5893ef9a9b84
Merged revisions 77842 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
58088
diff
changeset
|
77 PyAPI_FUNC(PY_LONG_LONG) PyLong_AsLongLongAndOverflow(PyObject *, int *); |
|
9044
d437b6683e24
Patch by Mark Hammond to support 64-bit ints on MS platforms.
Guido van Rossum <guido@python.org>
parents:
8822
diff
changeset
|
78 #endif /* HAVE_LONG_LONG */ |
|
8822
bd47ee068b83
Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents:
4870
diff
changeset
|
79 |
|
24752
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24210
diff
changeset
|
80 PyAPI_FUNC(PyObject *) PyLong_FromString(char *, char **, int); |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
64301
diff
changeset
|
81 #ifndef Py_LIMITED_API |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
33540
diff
changeset
|
82 PyAPI_FUNC(PyObject *) PyLong_FromUnicode(Py_UNICODE*, Py_ssize_t, int); |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
64301
diff
changeset
|
83 #endif |
|
1329
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
84 |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
64301
diff
changeset
|
85 #ifndef Py_LIMITED_API |
|
27549
7fcdeeb16ec0
_PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents:
27487
diff
changeset
|
86 /* _PyLong_Sign. Return 0 if v is 0, -1 if v < 0, +1 if v > 0. |
|
7fcdeeb16ec0
_PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents:
27487
diff
changeset
|
87 v must not be NULL, and must be a normalized long. |
|
7fcdeeb16ec0
_PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents:
27487
diff
changeset
|
88 There are no error cases. |
|
7fcdeeb16ec0
_PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents:
27487
diff
changeset
|
89 */ |
|
7fcdeeb16ec0
_PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents:
27487
diff
changeset
|
90 PyAPI_FUNC(int) _PyLong_Sign(PyObject *v); |
|
7fcdeeb16ec0
_PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents:
27487
diff
changeset
|
91 |
|
7fcdeeb16ec0
_PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents:
27487
diff
changeset
|
92 |
|
7fcdeeb16ec0
_PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents:
27487
diff
changeset
|
93 /* _PyLong_NumBits. Return the number of bits needed to represent the |
|
7fcdeeb16ec0
_PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents:
27487
diff
changeset
|
94 absolute value of a long. For example, this returns 1 for 1 and -1, 2 |
|
7fcdeeb16ec0
_PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents:
27487
diff
changeset
|
95 for 2 and -2, and 2 for 3 and -3. It returns 0 for 0. |
|
27487
0904d878b8f1
Added new private API function _PyLong_NumBits. This will be used at the
Tim Peters <tim.peters@gmail.com>
parents:
24752
diff
changeset
|
96 v must not be NULL, and must be a normalized long. |
|
0904d878b8f1
Added new private API function _PyLong_NumBits. This will be used at the
Tim Peters <tim.peters@gmail.com>
parents:
24752
diff
changeset
|
97 (size_t)-1 is returned and OverflowError set if the true result doesn't |
|
0904d878b8f1
Added new private API function _PyLong_NumBits. This will be used at the
Tim Peters <tim.peters@gmail.com>
parents:
24752
diff
changeset
|
98 fit in a size_t. |
|
0904d878b8f1
Added new private API function _PyLong_NumBits. This will be used at the
Tim Peters <tim.peters@gmail.com>
parents:
24752
diff
changeset
|
99 */ |
|
0904d878b8f1
Added new private API function _PyLong_NumBits. This will be used at the
Tim Peters <tim.peters@gmail.com>
parents:
24752
diff
changeset
|
100 PyAPI_FUNC(size_t) _PyLong_NumBits(PyObject *v); |
|
0904d878b8f1
Added new private API function _PyLong_NumBits. This will be used at the
Tim Peters <tim.peters@gmail.com>
parents:
24752
diff
changeset
|
101 |
|
62154
0d9347934cc5
Fix naming inconsistency.
Mark Dickinson <dickinsm@gmail.com>
parents:
61924
diff
changeset
|
102 /* _PyLong_DivmodNear. Given integers a and b, compute the nearest |
|
61924
81a580d947ef
Issue #8817: Expose round-to-nearest variant of divmod in _PyLong_Divmod_Near
Mark Dickinson <dickinsm@gmail.com>
parents:
59625
diff
changeset
|
103 integer q to the exact quotient a / b, rounding to the nearest even integer |
|
81a580d947ef
Issue #8817: Expose round-to-nearest variant of divmod in _PyLong_Divmod_Near
Mark Dickinson <dickinsm@gmail.com>
parents:
59625
diff
changeset
|
104 in the case of a tie. Return (q, r), where r = a - q*b. The remainder r |
|
81a580d947ef
Issue #8817: Expose round-to-nearest variant of divmod in _PyLong_Divmod_Near
Mark Dickinson <dickinsm@gmail.com>
parents:
59625
diff
changeset
|
105 will satisfy abs(r) <= abs(b)/2, with equality possible only if q is |
|
81a580d947ef
Issue #8817: Expose round-to-nearest variant of divmod in _PyLong_Divmod_Near
Mark Dickinson <dickinsm@gmail.com>
parents:
59625
diff
changeset
|
106 even. |
|
81a580d947ef
Issue #8817: Expose round-to-nearest variant of divmod in _PyLong_Divmod_Near
Mark Dickinson <dickinsm@gmail.com>
parents:
59625
diff
changeset
|
107 */ |
|
62154
0d9347934cc5
Fix naming inconsistency.
Mark Dickinson <dickinsm@gmail.com>
parents:
61924
diff
changeset
|
108 PyAPI_FUNC(PyObject *) _PyLong_DivmodNear(PyObject *, PyObject *); |
|
61924
81a580d947ef
Issue #8817: Expose round-to-nearest variant of divmod in _PyLong_Divmod_Near
Mark Dickinson <dickinsm@gmail.com>
parents:
59625
diff
changeset
|
109 |
|
18082
dd09f11fa40d
Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
110 /* _PyLong_FromByteArray: View the n unsigned bytes as a binary integer in |
|
dd09f11fa40d
Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
111 base 256, and return a Python long with the same numeric value. |
|
dd09f11fa40d
Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
112 If n is 0, the integer is 0. Else: |
|
dd09f11fa40d
Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
113 If little_endian is 1/true, bytes[n-1] is the MSB and bytes[0] the LSB; |
|
dd09f11fa40d
Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
114 else (little_endian is 0/false) bytes[0] is the MSB and bytes[n-1] the |
|
dd09f11fa40d
Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
115 LSB. |
|
dd09f11fa40d
Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
116 If is_signed is 0/false, view the bytes as a non-negative integer. |
|
dd09f11fa40d
Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
117 If is_signed is 1/true, view the bytes as a 2's-complement integer, |
|
dd09f11fa40d
Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
118 non-negative if bit 0x80 of the MSB is clear, negative if set. |
|
dd09f11fa40d
Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
119 Error returns: |
|
dd09f11fa40d
Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
120 + Return NULL with the appropriate exception set if there's not |
|
dd09f11fa40d
Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
121 enough memory to create the Python long. |
|
dd09f11fa40d
Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
122 */ |
|
24752
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24210
diff
changeset
|
123 PyAPI_FUNC(PyObject *) _PyLong_FromByteArray( |
|
18082
dd09f11fa40d
Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
124 const unsigned char* bytes, size_t n, |
|
dd09f11fa40d
Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
125 int little_endian, int is_signed); |
|
dd09f11fa40d
Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
126 |
|
dd09f11fa40d
Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
127 /* _PyLong_AsByteArray: Convert the least-significant 8*n bits of long |
|
dd09f11fa40d
Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
128 v to a base-256 integer, stored in array bytes. Normally return 0, |
|
dd09f11fa40d
Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
129 return -1 on error. |
|
dd09f11fa40d
Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
130 If little_endian is 1/true, store the MSB at bytes[n-1] and the LSB at |
|
dd09f11fa40d
Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
131 bytes[0]; else (little_endian is 0/false) store the MSB at bytes[0] and |
|
dd09f11fa40d
Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
132 the LSB at bytes[n-1]. |
|
dd09f11fa40d
Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
133 If is_signed is 0/false, it's an error if v < 0; else (v >= 0) n bytes |
|
dd09f11fa40d
Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
134 are filled and there's nothing special about bit 0x80 of the MSB. |
|
dd09f11fa40d
Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
135 If is_signed is 1/true, bytes is filled with the 2's-complement |
|
dd09f11fa40d
Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
136 representation of v's value. Bit 0x80 of the MSB is the sign bit. |
|
dd09f11fa40d
Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
137 Error returns (-1): |
|
dd09f11fa40d
Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
138 + is_signed is 0 and v < 0. TypeError is set in this case, and bytes |
|
dd09f11fa40d
Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
139 isn't altered. |
|
dd09f11fa40d
Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
140 + n isn't big enough to hold the full mathematical value of v. For |
|
dd09f11fa40d
Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
141 example, if is_signed is 0 and there are more digits in the v than |
|
dd09f11fa40d
Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
142 fit in n; or if is_signed is 1, v < 0, and n is just 1 bit shy of |
|
dd09f11fa40d
Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
143 being large enough to hold a sign bit. OverflowError is set in this |
|
dd09f11fa40d
Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
144 case, but bytes holds the least-signficant n bytes of the true value. |
|
dd09f11fa40d
Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
145 */ |
|
24752
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
24210
diff
changeset
|
146 PyAPI_FUNC(int) _PyLong_AsByteArray(PyLongObject* v, |
|
18082
dd09f11fa40d
Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
147 unsigned char* bytes, size_t n, |
|
dd09f11fa40d
Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
148 int little_endian, int is_signed); |
|
dd09f11fa40d
Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents:
14869
diff
changeset
|
149 |
|
42084
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
150 |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
151 /* _PyLong_Format: Convert the long to a string object with given base, |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
152 appending a base prefix of 0[box] if base is 2, 8 or 16. */ |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
153 PyAPI_FUNC(PyObject *) _PyLong_Format(PyObject *aa, int base); |
|
229c28cb9afb
Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
154 |
|
47393
0da27fdf0192
Refactor and clean up str.format() code (and helpers) in advance of optimizations.
Eric Smith <eric@trueblade.com>
parents:
44366
diff
changeset
|
155 /* Format the object based on the format_spec, as defined in PEP 3101 |
|
0da27fdf0192
Refactor and clean up str.format() code (and helpers) in advance of optimizations.
Eric Smith <eric@trueblade.com>
parents:
44366
diff
changeset
|
156 (Advanced String Formatting). */ |
|
0da27fdf0192
Refactor and clean up str.format() code (and helpers) in advance of optimizations.
Eric Smith <eric@trueblade.com>
parents:
44366
diff
changeset
|
157 PyAPI_FUNC(PyObject *) _PyLong_FormatAdvanced(PyObject *obj, |
|
0da27fdf0192
Refactor and clean up str.format() code (and helpers) in advance of optimizations.
Eric Smith <eric@trueblade.com>
parents:
44366
diff
changeset
|
158 Py_UNICODE *format_spec, |
|
0da27fdf0192
Refactor and clean up str.format() code (and helpers) in advance of optimizations.
Eric Smith <eric@trueblade.com>
parents:
44366
diff
changeset
|
159 Py_ssize_t format_spec_len); |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
64301
diff
changeset
|
160 #endif /* Py_LIMITED_API */ |
|
47393
0da27fdf0192
Refactor and clean up str.format() code (and helpers) in advance of optimizations.
Eric Smith <eric@trueblade.com>
parents:
44366
diff
changeset
|
161 |
|
44107
4e1d6491367c
I've moved the remains of PyInt_ to the longobject.h header file and removed the inclusing of intobject.h from Python.h. Now the intobject.h exists only to provide some aliases for porters from Python 2.x.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
162 /* These aren't really part of the long object, but they're handy. The |
|
4e1d6491367c
I've moved the remains of PyInt_ to the longobject.h header file and removed the inclusing of intobject.h from Python.h. Now the intobject.h exists only to provide some aliases for porters from Python 2.x.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
163 functions are in Python/mystrtoul.c. |
|
4e1d6491367c
I've moved the remains of PyInt_ to the longobject.h header file and removed the inclusing of intobject.h from Python.h. Now the intobject.h exists only to provide some aliases for porters from Python 2.x.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
164 */ |
|
4e1d6491367c
I've moved the remains of PyInt_ to the longobject.h header file and removed the inclusing of intobject.h from Python.h. Now the intobject.h exists only to provide some aliases for porters from Python 2.x.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
165 PyAPI_FUNC(unsigned long) PyOS_strtoul(char *, char **, int); |
|
4e1d6491367c
I've moved the remains of PyInt_ to the longobject.h header file and removed the inclusing of intobject.h from Python.h. Now the intobject.h exists only to provide some aliases for porters from Python 2.x.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
166 PyAPI_FUNC(long) PyOS_strtol(char *, char **, int); |
|
4e1d6491367c
I've moved the remains of PyInt_ to the longobject.h header file and removed the inclusing of intobject.h from Python.h. Now the intobject.h exists only to provide some aliases for porters from Python 2.x.
Christian Heimes <christian@cheimes.de>
parents:
44099
diff
changeset
|
167 |
|
1329
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
168 #ifdef __cplusplus |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
169 } |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
170 #endif |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
171 #endif /* !Py_LONGOBJECT_H */ |
