summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2003-01-28 20:37:45 (GMT)
committerTim Peters <tim.peters@gmail.com>2003-01-28 20:37:45 (GMT)
commitbaefd9e552723c6489c69cf5df93f82b473550a2 (patch)
tree25300bbc824f4b60c7c7ac1a352d9246ab0e2169 /Include
parent3d8c01b31c1a58d2181f78c5df2b0e79131046c0 (diff)
downloadcpython-baefd9e552723c6489c69cf5df93f82b473550a2.zip
cpython-baefd9e552723c6489c69cf5df93f82b473550a2.tar.gz
cpython-baefd9e552723c6489c69cf5df93f82b473550a2.tar.bz2
Added new private API function _PyLong_NumBits. This will be used at the
start for the C implemention of new pickle LONG1 and LONG4 opcodes (the linear-time way to pickle a long is to call _PyLong_AsByteArray, but the caller has no idea how big an array to allocate, and correct calculation is a bit subtle).
Diffstat (limited to 'Include')
-rw-r--r--Include/longobject.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/Include/longobject.h b/Include/longobject.h
index e452f516..3b808fb 100644
--- a/Include/longobject.h
+++ b/Include/longobject.h
@@ -44,6 +44,17 @@ PyAPI_FUNC(PyObject *) PyLong_FromString(char *, char **, int);
PyAPI_FUNC(PyObject *) PyLong_FromUnicode(Py_UNICODE*, int, int);
#endif
+/* _PyLong_NumBits. Return the number of bits needed to represent a long
+ in contiguous 2's-complement form, including 1 for the sign bit. For
+ example, this returns 1 for 0, and 2 for 1 and -1. Note that the
+ ceiling of this divided by 8 is the number of bytes needed by
+ _PyLong_AsByteArray to store the long in 256's-complement form.
+ v must not be NULL, and must be a normalized long.
+ (size_t)-1 is returned and OverflowError set if the true result doesn't
+ fit in a size_t.
+*/
+PyAPI_FUNC(size_t) _PyLong_NumBits(PyObject *v);
+
/* _PyLong_FromByteArray: View the n unsigned bytes as a binary integer in
base 256, and return a Python long with the same numeric value.
If n is 0, the integer is 0. Else: