[Python-checkins] cpython: Issue #1172711: Add 'long long' support to the array module.
Ezio Melotti
ezio.melotti at gmail.com
Wed Sep 21 15:25:29 CEST 2011
Hi,
On 21/09/2011 4.04, meador.inge wrote:
> http://hg.python.org/cpython/rev/15659e0e2b2e
> changeset: 72430:15659e0e2b2e
> user: Meador Inge<meadori at gmail.com>
> date: Tue Sep 20 19:55:51 2011 -0500
> summary:
> Issue #1172711: Add 'long long' support to the array module.
>
> Initial patch by Oren Tirosh and Hirokazu Yamamoto.
>
> files:
> Doc/library/array.rst | 66 ++++++++++++++----------
> Lib/test/test_array.py | 21 +++++++
> Misc/NEWS | 3 +
> Modules/arraymodule.c | 79 +++++++++++++++++++++++++++++-
> 4 files changed, 141 insertions(+), 28 deletions(-)
>
>
> diff --git a/Doc/library/array.rst b/Doc/library/array.rst
> --- a/Doc/library/array.rst
> +++ b/Doc/library/array.rst
> @@ -14,37 +14,49 @@
> :dfn:`type code`, which is a single character. The following type codes are
> defined:
>
> -+-----------+----------------+-------------------+-----------------------+
> -| Type code | C Type | Python Type | Minimum size in bytes |
> -+===========+================+===================+=======================+
> -| ``'b'`` | signed char | int | 1 |
> -+-----------+----------------+-------------------+-----------------------+
> -| ``'B'`` | unsigned char | int | 1 |
> -+-----------+----------------+-------------------+-----------------------+
> -| ``'u'`` | Py_UNICODE | Unicode character | 2 (see note) |
> -+-----------+----------------+-------------------+-----------------------+
> -| ``'h'`` | signed short | int | 2 |
> -+-----------+----------------+-------------------+-----------------------+
> -| ``'H'`` | unsigned short | int | 2 |
> -+-----------+----------------+-------------------+-----------------------+
> -| ``'i'`` | signed int | int | 2 |
> -+-----------+----------------+-------------------+-----------------------+
> -| ``'I'`` | unsigned int | int | 2 |
> -+-----------+----------------+-------------------+-----------------------+
> -| ``'l'`` | signed long | int | 4 |
> -+-----------+----------------+-------------------+-----------------------+
> -| ``'L'`` | unsigned long | int | 4 |
> -+-----------+----------------+-------------------+-----------------------+
> -| ``'f'`` | float | float | 4 |
> -+-----------+----------------+-------------------+-----------------------+
> -| ``'d'`` | double | float | 8 |
> -+-----------+----------------+-------------------+-----------------------+
> ++-----------+--------------------+-------------------+-----------------------+-------+
> +| Type code | C Type | Python Type | Minimum size in bytes | Notes |
> ++===========+====================+===================+=======================+=======+
> +| ``'b'`` | signed char | int | 1 | |
> ++-----------+--------------------+-------------------+-----------------------+-------+
> +| ``'B'`` | unsigned char | int | 1 | |
> ++-----------+--------------------+-------------------+-----------------------+-------+
> +| ``'u'`` | Py_UNICODE | Unicode character | 2 | \(1) |
> ++-----------+--------------------+-------------------+-----------------------+-------+
> +| ``'h'`` | signed short | int | 2 | |
> ++-----------+--------------------+-------------------+-----------------------+-------+
> +| ``'H'`` | unsigned short | int | 2 | |
> ++-----------+--------------------+-------------------+-----------------------+-------+
> +| ``'i'`` | signed int | int | 2 | |
> ++-----------+--------------------+-------------------+-----------------------+-------+
> +| ``'I'`` | unsigned int | int | 2 | |
> ++-----------+--------------------+-------------------+-----------------------+-------+
> +| ``'l'`` | signed long | int | 4 | |
> ++-----------+--------------------+-------------------+-----------------------+-------+
> +| ``'L'`` | unsigned long | int | 4 | |
> ++-----------+--------------------+-------------------+-----------------------+-------+
> +| ``'q'`` | signed long long | int | 8 | \(2) |
> ++-----------+--------------------+-------------------+-----------------------+-------+
> +| ``'Q'`` | unsigned long long | int | 8 | \(2) |
> ++-----------+--------------------+-------------------+-----------------------+-------+
> +| ``'f'`` | float | float | 4 | |
> ++-----------+--------------------+-------------------+-----------------------+-------+
> +| ``'d'`` | double | float | 8 | |
> ++-----------+--------------------+-------------------+-----------------------+-------+
>
> -.. note::
> +Notes:
>
> - The ``'u'`` typecode corresponds to Python's unicode character. On narrow
> +(1)
> + The ``'u'`` type code corresponds to Python's unicode character. On narrow
> Unicode builds this is 2-bytes, on wide builds this is 4-bytes.
>
> +(2)
> + The ``'q'`` and ``'Q'`` type codes are available only if
> + the platform C compiler used to build Python supports C :ctype:`long long`,
> + or, on Windows, :ctype:`__int64`.
> +
> + .. versionadded:: 3.3
> +
> The actual representation of values is determined by the machine architecture
> (strictly speaking, by the C implementation). The actual size can be accessed
> through the :attr:`itemsize` attribute.
> diff --git a/Lib/test/test_array.py b/Lib/test/test_array.py
> --- a/Lib/test/test_array.py
> +++ b/Lib/test/test_array.py
> @@ -16,6 +16,13 @@
> import array
> from array import _array_reconstructor as array_reconstructor
>
> +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
> @@ -26,6 +33,8 @@
>
> tests = [] # list to accumulate all tests
> typecodes = "ubBhHiIlLfd"
> +if have_long_long:
> + typecodes += 'qQ'
>
> class BadConstructorTest(unittest.TestCase):
>
> @@ -1205,6 +1214,18 @@
> minitemsize = 4
> tests.append(UnsignedLongTest)
>
> + at unittest.skipIf(not have_long_long, 'need long long support')
I think this would read better with skipUnless and s/have/has/:
@unittest.skipUnless(HAS_LONG_LONG, 'need long long support')
> +class LongLongTest(SignedNumberTest):
> + typecode = 'q'
> + minitemsize = 8
> +tests.append(LongLongTest)
> +
> + at unittest.skipIf(not have_long_long, 'need long long support')
> +class UnsignedLongLongTest(UnsignedNumberTest):
> + typecode = 'Q'
> + minitemsize = 8
> +tests.append(UnsignedLongLongTest)
> +
> class FPTest(NumberTest):
> example = [-42.0, 0, 42, 1e5, -1e10]
> smallerexample = [-42.0, 0, 42, 1e5, -2e10]
>
> [...]
Best Regards,
Ezio Melotti
More information about the Python-checkins
mailing list