Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(17575)

Unified Diff: Modules/arraymodule.c

Issue 1172711: long long support for array module
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Lib/test/test_array.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Modules/arraymodule.c Thu Sep 08 19:29:07 2011 -0700
+++ b/Modules/arraymodule.c Thu Sep 08 21:59:36 2011 -0500
@@ -356,6 +356,59 @@
return 0;
}
+#ifdef HAVE_LONG_LONG
+
+static PyObject *
+q_getitem(arrayobject *ap, int i)
skrah 2011/09/11 10:53:59 'int i' should be 'Py_ssize_t i' (also in other pl
meadori 2011/09/11 16:43:38 Fixed.
+{
+ 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))
skrah 2011/09/11 10:53:59 Why not use PyLong_AsLongLong() directly. I see th
meadori 2011/09/11 16:43:38 The only reason that I can see is that 'PyArg_Pars
+ 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 PY_LONG_LONG) -1 && PyErr_Occurred())
+ return -1;
+ }
+ else {
skrah 2011/09/11 10:53:59 All PyArg_Parse() does in the test suite is raise
meadori 2011/09/11 16:43:38 Maybe the tests needed extending. Replacing this
+ 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, Py_ssize_t i)
{
@@ -406,6 +459,10 @@
{'I', sizeof(int), II_getitem, II_setitem, "I", 1, 0},
{'l', sizeof(long), l_getitem, l_setitem, "l", 1, 1},
{'L', sizeof(long), LL_getitem, LL_setitem, "L", 1, 0},
+#ifdef HAVE_LONG_LONG
+ {'q', sizeof(PY_LONG_LONG), q_getitem, q_setitem, "q", 1, 1},
+ {'Q', sizeof(PY_LONG_LONG), QQ_getitem, QQ_setitem, "Q", 1, 0},
+#endif
{'f', sizeof(float), f_getitem, f_setitem, "f", 0, 0},
{'d', sizeof(double), d_getitem, d_setitem, "d", 0, 0},
{'\0', 0, 0, 0, 0, 0, 0} /* Sentinel */
@@ -1655,6 +1712,16 @@
intsize = sizeof(long);
is_signed = 0;
break;
+#if HAVE_LONG_LONG
+ case 'q':
+ intsize = sizeof(PY_LONG_LONG);
+ is_signed = 1;
+ break;
+ case 'Q':
+ intsize = sizeof(PY_LONG_LONG);
+ is_signed = 0;
+ break;
+#endif
default:
return UNKNOWN_FORMAT;
}
@@ -2501,7 +2568,11 @@
}
}
PyErr_SetString(PyExc_ValueError,
+#ifdef HAVE_LONG_LONG
+ "bad typecode (must be b, B, u, h, H, i, I, l, L, q, Q, f or d)");
+#else
"bad typecode (must be b, B, u, h, H, i, I, l, L, f or d)");
+#endif
return NULL;
}
@@ -2524,12 +2595,18 @@
'I' unsigned integer 2 \n\
'l' signed integer 4 \n\
'L' unsigned integer 4 \n\
+ 'q' signed integer 8 (see note) \n\
+ 'Q' unsigned integer 8 (see note) \n\
'f' floating point 4 \n\
'd' floating point 8 \n\
\n\
-NOTE: The 'u' typecode corresponds to Python's unicode character. On \n\
+NOTE: The 'u' type code corresponds to Python's unicode character. On \n\
narrow builds this is 2-bytes on wide builds this is 4-bytes.\n\
\n\
+NOTE: The 'q' and 'Q' type codes are only available if the platform \n\
+C compiler used to build Python supports 'long long', or, on Windows, \n\
+'__int64'.\n\
+\n\
The constructor is:\n\
\n\
array(typecode [, initializer]) -- create a new array\n\
« no previous file with comments | « Lib/test/test_array.py ('k') | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+