annotate Include/longobject.h @ 87690:66c1c9f32567 default tip

Add use_weakref option to functools.lru_cache The use_weakref option makes lru_cache create weak references to the function arguments when creating the cache key, which prevents them from staying in the memory forever even after all other references to them are gone. This is a proof of concept for http://bugs.python.org/issue19859
author Radomir Dopieralski <devel@sheep.art.pl>
date Tue, 03 Dec 2013 16:02:48 +0100
parents 3055e61f1e66
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
7ba9612058a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
7
7ba9612058a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 /* Long (arbitrary precision) integer object interface */
7ba9612058a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
7ba9612058a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
13
40909
f2f0b41f270d Merged revisions 53875-53911 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 40626
diff changeset
14 #define PyLong_Check(op) \
72504
950678c769e6 Clean up a few tabs that went in with PEP393.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 72475
diff changeset
15 PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_LONG_SUBCLASS)
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
16 #define PyLong_CheckExact(op) (Py_TYPE(op) == &PyLong_Type)
230
7ba9612058a4 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
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: 38301
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: 38301
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: 38301
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 *);
81587
974ace29ee2d Issue #15989: Fix several occurrences of integer overflow
Serhiy Storchaka <storchaka@gmail.com>
parents: 68257
diff changeset
29 #ifndef Py_LIMITED_API
974ace29ee2d Issue #15989: Fix several occurrences of integer overflow
Serhiy Storchaka <storchaka@gmail.com>
parents: 68257
diff changeset
30 PyAPI_FUNC(int) _PyLong_AsInt(PyObject *);
974ace29ee2d Issue #15989: Fix several occurrences of integer overflow
Serhiy Storchaka <storchaka@gmail.com>
parents: 68257
diff changeset
31 #endif
52215
bb5de24a343f Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents: 50656
diff changeset
32 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
33
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
34 /* 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
35 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
36 #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
37
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 /* 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
39 #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
40 #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
41 #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
42 #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
43 #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
44 #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
45 #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
46 #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
47 #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
48 #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
49 #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
50 #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
51 #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
52 #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
53 #endif /* SIZEOF_PID_T */
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 33540
diff changeset
54
84045
0410bf251e10 Issue #17931: Resolve confusion on Windows between pids and process handles.
Richard Oudkerk <shibturn@gmail.com>
parents: 81589
diff changeset
55 #if SIZEOF_VOID_P == SIZEOF_INT
0410bf251e10 Issue #17931: Resolve confusion on Windows between pids and process handles.
Richard Oudkerk <shibturn@gmail.com>
parents: 81589
diff changeset
56 # define _Py_PARSE_INTPTR "i"
0410bf251e10 Issue #17931: Resolve confusion on Windows between pids and process handles.
Richard Oudkerk <shibturn@gmail.com>
parents: 81589
diff changeset
57 # define _Py_PARSE_UINTPTR "I"
0410bf251e10 Issue #17931: Resolve confusion on Windows between pids and process handles.
Richard Oudkerk <shibturn@gmail.com>
parents: 81589
diff changeset
58 #elif SIZEOF_VOID_P == SIZEOF_LONG
0410bf251e10 Issue #17931: Resolve confusion on Windows between pids and process handles.
Richard Oudkerk <shibturn@gmail.com>
parents: 81589
diff changeset
59 # define _Py_PARSE_INTPTR "l"
0410bf251e10 Issue #17931: Resolve confusion on Windows between pids and process handles.
Richard Oudkerk <shibturn@gmail.com>
parents: 81589
diff changeset
60 # define _Py_PARSE_UINTPTR "k"
0410bf251e10 Issue #17931: Resolve confusion on Windows between pids and process handles.
Richard Oudkerk <shibturn@gmail.com>
parents: 81589
diff changeset
61 #elif defined(SIZEOF_LONG_LONG) && SIZEOF_VOID_P == SIZEOF_LONG_LONG
0410bf251e10 Issue #17931: Resolve confusion on Windows between pids and process handles.
Richard Oudkerk <shibturn@gmail.com>
parents: 81589
diff changeset
62 # define _Py_PARSE_INTPTR "L"
0410bf251e10 Issue #17931: Resolve confusion on Windows between pids and process handles.
Richard Oudkerk <shibturn@gmail.com>
parents: 81589
diff changeset
63 # define _Py_PARSE_UINTPTR "K"
0410bf251e10 Issue #17931: Resolve confusion on Windows between pids and process handles.
Richard Oudkerk <shibturn@gmail.com>
parents: 81589
diff changeset
64 #else
0410bf251e10 Issue #17931: Resolve confusion on Windows between pids and process handles.
Richard Oudkerk <shibturn@gmail.com>
parents: 81589
diff changeset
65 # error "void* different in size from int, long and long long"
0410bf251e10 Issue #17931: Resolve confusion on Windows between pids and process handles.
Richard Oudkerk <shibturn@gmail.com>
parents: 81589
diff changeset
66 #endif /* SIZEOF_VOID_P */
0410bf251e10 Issue #17931: Resolve confusion on Windows between pids and process handles.
Richard Oudkerk <shibturn@gmail.com>
parents: 81589
diff changeset
67
62558
ec0fd5a6bb45 Issue #9089: Remove references to intobject.c and intobject.h from comments.
Mark Dickinson <dickinsm@gmail.com>
parents: 62154
diff changeset
68 /* Used by Python/mystrtoul.c. */
66664
62b61abd02b8 Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents: 64301
diff changeset
69 #ifndef Py_LIMITED_API
50656
c7c344b63ecc Reduce the size of the _PyLong_DigitValue table.
Raymond Hettinger <python@rcn.com>
parents: 47393
diff changeset
70 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
71 #endif
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 33540
diff changeset
72
58088
46d60e5ff103 Merged revisions 77234 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 52215
diff changeset
73 /* _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
74 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
75 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
76 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
77 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
78 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
79 #ifndef Py_LIMITED_API
58088
46d60e5ff103 Merged revisions 77234 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 52215
diff changeset
80 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
81 #endif
19671
7df300d284c6 Introduce new private API function _PyLong_AsScaledDouble. Not used yet,
Tim Peters <tim.peters@gmail.com>
parents: 19550
diff changeset
82
24752
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 24210
diff changeset
83 PyAPI_FUNC(double) PyLong_AsDouble(PyObject *);
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 24210
diff changeset
84 PyAPI_FUNC(PyObject *) PyLong_FromVoidPtr(void *);
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 24210
diff changeset
85 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
86
8822
bd47ee068b83 Changes for BeOS, QNX and long long, by Chris Herborth.
Guido van Rossum <guido@python.org>
parents: 4870
diff changeset
87 #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
88 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
89 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
90 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
91 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
92 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
93 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
94 #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
95
86484
3055e61f1e66 Issue #1772673: The type of `char*` arguments now changed to `const char*`.
Serhiy Storchaka <storchaka@gmail.com>
parents: 85419
diff changeset
96 PyAPI_FUNC(PyObject *) PyLong_FromString(const char *, char **, int);
66664
62b61abd02b8 Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents: 64301
diff changeset
97 #ifndef Py_LIMITED_API
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 33540
diff changeset
98 PyAPI_FUNC(PyObject *) PyLong_FromUnicode(Py_UNICODE*, Py_ssize_t, int);
72475
8beaa9a37387 Implement PEP 393.
Martin v. Löwis <martin@v.loewis.de>
parents: 68257
diff changeset
99 PyAPI_FUNC(PyObject *) PyLong_FromUnicodeObject(PyObject *u, int base);
84995
ecc8512b427d Issue #16741: Fix an error reporting in int().
Serhiy Storchaka <storchaka@gmail.com>
parents: 81588
diff changeset
100 PyAPI_FUNC(PyObject *) _PyLong_FromBytes(const char *, Py_ssize_t, int);
66664
62b61abd02b8 Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents: 64301
diff changeset
101 #endif
1329
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
102
66664
62b61abd02b8 Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents: 64301
diff changeset
103 #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
104 /* _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
105 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
106 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
107 */
7fcdeeb16ec0 _PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents: 27487
diff changeset
108 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
109
7fcdeeb16ec0 _PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents: 27487
diff changeset
110
7fcdeeb16ec0 _PyLong_NumBits(): The definition of this was too specific to the quirky
Tim Peters <tim.peters@gmail.com>
parents: 27487
diff changeset
111 /* _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
112 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
113 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
114 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
115 (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
116 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
117 */
0904d878b8f1 Added new private API function _PyLong_NumBits. This will be used at the
Tim Peters <tim.peters@gmail.com>
parents: 24752
diff changeset
118 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
119
62154
0d9347934cc5 Fix naming inconsistency.
Mark Dickinson <dickinsm@gmail.com>
parents: 61924
diff changeset
120 /* _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
121 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
122 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
123 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
124 even.
81a580d947ef Issue #8817: Expose round-to-nearest variant of divmod in _PyLong_Divmod_Near
Mark Dickinson <dickinsm@gmail.com>
parents: 59625
diff changeset
125 */
62154
0d9347934cc5 Fix naming inconsistency.
Mark Dickinson <dickinsm@gmail.com>
parents: 61924
diff changeset
126 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
127
18082
dd09f11fa40d Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents: 14869
diff changeset
128 /* _PyLong_FromByteArray: View the n unsigned bytes as a binary integer in
85418
4d62a62ba44d Issue #18783: Removed existing mentions of Python long type in docstrings,
Serhiy Storchaka <storchaka@gmail.com>
parents: 84995
diff changeset
129 base 256, and return a Python int with the same numeric value.
18082
dd09f11fa40d Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents: 14869
diff changeset
130 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
131 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
132 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
133 LSB.
dd09f11fa40d Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents: 14869
diff changeset
134 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
135 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
136 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
137 Error returns:
dd09f11fa40d Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents: 14869
diff changeset
138 + Return NULL with the appropriate exception set if there's not
85418
4d62a62ba44d Issue #18783: Removed existing mentions of Python long type in docstrings,
Serhiy Storchaka <storchaka@gmail.com>
parents: 84995
diff changeset
139 enough memory to create the Python int.
18082
dd09f11fa40d Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents: 14869
diff changeset
140 */
24752
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 24210
diff changeset
141 PyAPI_FUNC(PyObject *) _PyLong_FromByteArray(
72504
950678c769e6 Clean up a few tabs that went in with PEP393.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 72475
diff changeset
142 const unsigned char* bytes, size_t n,
950678c769e6 Clean up a few tabs that went in with PEP393.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 72475
diff changeset
143 int little_endian, int is_signed);
18082
dd09f11fa40d Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents: 14869
diff changeset
144
dd09f11fa40d Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents: 14869
diff changeset
145 /* _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
146 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
147 return -1 on error.
dd09f11fa40d Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents: 14869
diff changeset
148 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
149 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
150 the LSB at bytes[n-1].
dd09f11fa40d Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents: 14869
diff changeset
151 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
152 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
153 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
154 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
155 Error returns (-1):
dd09f11fa40d Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents: 14869
diff changeset
156 + 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
157 isn't altered.
dd09f11fa40d Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents: 14869
diff changeset
158 + 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
159 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
160 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
161 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
162 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
163 */
24752
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 24210
diff changeset
164 PyAPI_FUNC(int) _PyLong_AsByteArray(PyLongObject* v,
72504
950678c769e6 Clean up a few tabs that went in with PEP393.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 72475
diff changeset
165 unsigned char* bytes, size_t n,
950678c769e6 Clean up a few tabs that went in with PEP393.
Ezio Melotti <ezio.melotti@gmail.com>
parents: 72475
diff changeset
166 int little_endian, int is_signed);
18082
dd09f11fa40d Two new private longobject API functions,
Tim Peters <tim.peters@gmail.com>
parents: 14869
diff changeset
167
42084
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41587
diff changeset
168
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41587
diff changeset
169 /* _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
170 appending a base prefix of 0[box] if base is 2, 8 or 16. */
77223
22b56b0b8619 Issue #14744: Use the new _PyUnicodeWriter internal API to speed up str%args and str.format(args)
Victor Stinner <victor.stinner@gmail.com>
parents: 72504
diff changeset
171 PyAPI_FUNC(PyObject *) _PyLong_Format(PyObject *obj, int base);
22b56b0b8619 Issue #14744: Use the new _PyUnicodeWriter internal API to speed up str%args and str.format(args)
Victor Stinner <victor.stinner@gmail.com>
parents: 72504
diff changeset
172
22b56b0b8619 Issue #14744: Use the new _PyUnicodeWriter internal API to speed up str%args and str.format(args)
Victor Stinner <victor.stinner@gmail.com>
parents: 72504
diff changeset
173 PyAPI_FUNC(int) _PyLong_FormatWriter(
22b56b0b8619 Issue #14744: Use the new _PyUnicodeWriter internal API to speed up str%args and str.format(args)
Victor Stinner <victor.stinner@gmail.com>
parents: 72504
diff changeset
174 _PyUnicodeWriter *writer,
22b56b0b8619 Issue #14744: Use the new _PyUnicodeWriter internal API to speed up str%args and str.format(args)
Victor Stinner <victor.stinner@gmail.com>
parents: 72504
diff changeset
175 PyObject *obj,
22b56b0b8619 Issue #14744: Use the new _PyUnicodeWriter internal API to speed up str%args and str.format(args)
Victor Stinner <victor.stinner@gmail.com>
parents: 72504
diff changeset
176 int base,
22b56b0b8619 Issue #14744: Use the new _PyUnicodeWriter internal API to speed up str%args and str.format(args)
Victor Stinner <victor.stinner@gmail.com>
parents: 72504
diff changeset
177 int alternate);
42084
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 41587
diff changeset
178
47393
0da27fdf0192 Refactor and clean up str.format() code (and helpers) in advance of optimizations.
Eric Smith <eric@trueblade.com>
parents: 44366
diff changeset
179 /* 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
180 (Advanced String Formatting). */
77223
22b56b0b8619 Issue #14744: Use the new _PyUnicodeWriter internal API to speed up str%args and str.format(args)
Victor Stinner <victor.stinner@gmail.com>
parents: 72504
diff changeset
181 PyAPI_FUNC(int) _PyLong_FormatAdvancedWriter(
22b56b0b8619 Issue #14744: Use the new _PyUnicodeWriter internal API to speed up str%args and str.format(args)
Victor Stinner <victor.stinner@gmail.com>
parents: 72504
diff changeset
182 _PyUnicodeWriter *writer,
22b56b0b8619 Issue #14744: Use the new _PyUnicodeWriter internal API to speed up str%args and str.format(args)
Victor Stinner <victor.stinner@gmail.com>
parents: 72504
diff changeset
183 PyObject *obj,
22b56b0b8619 Issue #14744: Use the new _PyUnicodeWriter internal API to speed up str%args and str.format(args)
Victor Stinner <victor.stinner@gmail.com>
parents: 72504
diff changeset
184 PyObject *format_spec,
22b56b0b8619 Issue #14744: Use the new _PyUnicodeWriter internal API to speed up str%args and str.format(args)
Victor Stinner <victor.stinner@gmail.com>
parents: 72504
diff changeset
185 Py_ssize_t start,
22b56b0b8619 Issue #14744: Use the new _PyUnicodeWriter internal API to speed up str%args and str.format(args)
Victor Stinner <victor.stinner@gmail.com>
parents: 72504
diff changeset
186 Py_ssize_t end);
66664
62b61abd02b8 Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents: 64301
diff changeset
187 #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
188
85418
4d62a62ba44d Issue #18783: Removed existing mentions of Python long type in docstrings,
Serhiy Storchaka <storchaka@gmail.com>
parents: 84995
diff changeset
189 /* These aren't really part of the int object, but they're handy. The
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
190 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
191 */
86484
3055e61f1e66 Issue #1772673: The type of `char*` arguments now changed to `const char*`.
Serhiy Storchaka <storchaka@gmail.com>
parents: 85419
diff changeset
192 PyAPI_FUNC(unsigned long) PyOS_strtoul(const char *, char **, int);
3055e61f1e66 Issue #1772673: The type of `char*` arguments now changed to `const char*`.
Serhiy Storchaka <storchaka@gmail.com>
parents: 85419
diff changeset
193 PyAPI_FUNC(long) PyOS_strtol(const char *, char **, int);
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
194
1329
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
195 #ifdef __cplusplus
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
196 }
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
197 #endif
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
198 #endif /* !Py_LONGOBJECT_H */