diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2009-03-20 15:51:55 (GMT) |
---|---|---|
committer | Mark Dickinson <dickinsm@gmail.com> | 2009-03-20 15:51:55 (GMT) |
commit | efc82f7e8eff19d8e844a3dc268a88de7fbcb173 (patch) | |
tree | 58198f2e7610ba6d33865884487de006de30af85 /Objects | |
parent | c8e81ef508f0f1dc4e5c31bd0bec2766867fead5 (diff) | |
download | cpython-efc82f7e8eff19d8e844a3dc268a88de7fbcb173.zip cpython-efc82f7e8eff19d8e844a3dc268a88de7fbcb173.tar.gz cpython-efc82f7e8eff19d8e844a3dc268a88de7fbcb173.tar.bz2 |
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Backport of r70459.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/longobject.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c index 9bd6378..e4e8859 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -6,6 +6,7 @@ #include "Python.h" #include "longintrepr.h" +#include "structseq.h" #include <ctype.h> #include <stddef.h> @@ -3646,3 +3647,51 @@ PyTypeObject PyLong_Type = { long_new, /* tp_new */ PyObject_Del, /* tp_free */ }; + +static PyTypeObject Long_InfoType; + +PyDoc_STRVAR(long_info__doc__, +"sys.long_info\n\ +\n\ +A struct sequence that holds information about Python's\n\ +internal representation of integers. The attributes are read only."); + +static PyStructSequence_Field long_info_fields[] = { + {"bits_per_digit", "size of a digit in bits"}, + {"sizeof_digit", "size in bytes of the C type used to " + "represent a digit"}, + {NULL, NULL} +}; + +static PyStructSequence_Desc long_info_desc = { + "sys.long_info", /* name */ + long_info__doc__, /* doc */ + long_info_fields, /* fields */ + 2 /* number of fields */ +}; + +PyObject * +PyLong_GetInfo(void) +{ + PyObject* long_info; + int field = 0; + long_info = PyStructSequence_New(&Long_InfoType); + if (long_info == NULL) + return NULL; + PyStructSequence_SET_ITEM(long_info, field++, PyLong_FromLong(PyLong_SHIFT)); + PyStructSequence_SET_ITEM(long_info, field++, PyLong_FromLong(sizeof(digit))); + if (PyErr_Occurred()) { + Py_CLEAR(long_info); + return NULL; + } + return long_info; +} + +int +_PyLong_Init(void) +{ + /* initialize long_info */ + if (Long_InfoType.tp_name == 0) + PyStructSequence_InitType(&Long_InfoType, &long_info_desc); + return 1; +} |