--- Modules/arraymodule.c.orig 2004-08-29 09:50:42.000000000 +0200 +++ Modules/arraymodule.c 2005-03-29 10:51:39.605469000 +0200 @@ -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 */ @@ -1877,7 +1933,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; } @@ -1901,6 +1961,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\ --- Lib/test/test_array.py.orig 2005-03-29 11:38:52.792922600 +0200 +++ Lib/test/test_array.py 2005-03-29 12:09:37.876380000 +0200 @@ -6,11 +6,22 @@ import unittest from test import test_support from weakref import proxy -import array, cStringIO, math +import array, cStringIO, math, struct + +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 tests = [] # list to accumulate all tests typecodes = "cubBhHiIlLfd" +if have_long_long: + typecodes += 'qQ' + class BadConstructorTest(unittest.TestCase): def test_constructor(self): @@ -889,6 +900,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] --- Objects/longobject.c.orig 2004-09-20 08:14:54.000000000 +0200 +++ Objects/longobject.c 2005-03-29 12:07:27.222638600 +0200 @@ -782,12 +782,8 @@ PyErr_BadInternalCall(); return -1; } - if (!PyLong_Check(vv)) { - if (PyInt_Check(vv)) - return (PY_LONG_LONG)PyInt_AsLong(vv); - PyErr_BadInternalCall(); - return -1; - } + if (!PyLong_Check(vv)) + return (PY_LONG_LONG)PyInt_AsLong(vv); res = _PyLong_AsByteArray( (PyLongObject *)vv, (unsigned char *)&bytes, @@ -821,7 +817,7 @@ /* Plan 9 can't handle PY_LONG_LONG in ? : expressions */ if (res < 0) - return (unsigned PY_LONG_LONG)res; + return (unsigned PY_LONG_LONG)-1; else return bytes; }