Index: Lib/test/test_array.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/test/test_array.py,v retrieving revision 1.32 diff -u -r1.32 test_array.py --- Lib/test/test_array.py 21 Jan 2005 21:16:51 -0000 1.32 +++ Lib/test/test_array.py 31 Mar 2005 22:00:18 -0000 @@ -6,15 +6,26 @@ import unittest from test import test_support from weakref import proxy -import array, cStringIO, math +import array, cStringIO, math, struct from cPickle import loads, dumps +try: + # Try to determine availability of long long independently + # of the array module under test + struct.calcsize('@q') + have_long_long = True +except struct.error: + have_long_long = False + class ArraySubclass(array.array): pass tests = [] # list to accumulate all tests typecodes = "cubBhHiIlLfd" +if have_long_long: + typecodes += 'qQ' + class BadConstructorTest(unittest.TestCase): def test_constructor(self): @@ -913,6 +924,18 @@ minitemsize = 4 tests.append(UnsignedLongTest) +class LongLongTest(SignedNumberTest): + typecode = 'q' + minitemsize = 8 + +class UnsignedLongLongTest(UnsignedNumberTest): + typecode = 'Q' + minitemsize = 8 + +if have_long_long: + tests.append(LongLongTest) + tests.append(UnsignedLongLongTest) + class FPTest(NumberTest): example = [-42.0, 0, 42, 1e5, -1e10] smallerexample = [-42.0, 0, 42, 1e5, -2e10] Index: Modules/arraymodule.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Modules/arraymodule.c,v retrieving revision 2.98 diff -u -r2.98 arraymodule.c --- Modules/arraymodule.c 16 Dec 2004 16:23:39 -0000 2.98 +++ Modules/arraymodule.c 31 Mar 2005 22:00:28 -0000 @@ -354,6 +354,58 @@ return 0; } +#ifdef HAVE_LONG_LONG + +static PyObject * +q_getitem(arrayobject *ap, int i) +{ + return PyLong_FromLongLong(((PY_LONG_LONG *)ap->ob_item)[i]); +} + +static int +q_setitem(arrayobject *ap, int i, PyObject *v) +{ + PY_LONG_LONG x; + if (!PyArg_Parse(v, "L;array item must be integer", &x)) + return -1; + if (i >= 0) + ((PY_LONG_LONG *)ap->ob_item)[i] = x; + return 0; +} + +static PyObject * +QQ_getitem(arrayobject *ap, int i) +{ + return PyLong_FromUnsignedLongLong(((unsigned PY_LONG_LONG*)ap->ob_item)[i]); +} + +static int +QQ_setitem(arrayobject *ap, int i, PyObject *v) +{ + unsigned PY_LONG_LONG x; + if (PyLong_Check(v)) { + x = PyLong_AsUnsignedLongLong(v); + if (x == (unsigned long long) -1 && PyErr_Occurred()) + return -1; + } + else { + PY_LONG_LONG y; + if (!PyArg_Parse(v, "L;array item must be integer", &y)) + return -1; + if (y < 0) { + PyErr_SetString(PyExc_OverflowError, + "unsigned long long is less than minimum"); + return -1; + } + x = (unsigned PY_LONG_LONG)y; + } + + if (i >= 0) + ((unsigned PY_LONG_LONG*)ap->ob_item)[i] = x; + return 0; +} +#endif + static PyObject * f_getitem(arrayobject *ap, int i) { @@ -402,6 +454,10 @@ {'I', sizeof(int), II_getitem, II_setitem}, {'l', sizeof(long), l_getitem, l_setitem}, {'L', sizeof(long), LL_getitem, LL_setitem}, +#ifdef HAVE_LONG_LONG + {'q', sizeof(PY_LONG_LONG), q_getitem, q_setitem}, + {'Q', sizeof(PY_LONG_LONG), QQ_getitem, QQ_setitem}, +#endif {'f', sizeof(float), f_getitem, f_setitem}, {'d', sizeof(double), d_getitem, d_setitem}, {'\0', 0, 0, 0} /* Sentinel */ @@ -1902,7 +1958,11 @@ } } PyErr_SetString(PyExc_ValueError, +#ifdef HAVE_LONG_LONG + "bad typecode (must be c, b, B, u, h, H, i, I, l, L, q, Q, f or d)"); +#else "bad typecode (must be c, b, B, u, h, H, i, I, l, L, f or d)"); +#endif return NULL; } @@ -1926,6 +1986,8 @@ 'I' unsigned integer 2 \n\ 'l' signed integer 4 \n\ 'L' unsigned integer 4 \n\ + 'q' signed integer 8 \n\ + 'Q' unsigned integer 8 \n\ 'f' floating point 4 \n\ 'd' floating point 8 \n\ \n\