Author: Matti Picus <matti.pi...@gmail.com> Branch: newmemoryview-app-level Changeset: r96156:96f4200d74ac Date: 2019-02-24 22:41 +0200 http://bitbucket.org/pypy/pypy/changeset/96f4200d74ac/
Log: cleanup, add test diff --git a/extra_tests/ctypes_tests/test_structures.py b/extra_tests/ctypes_tests/test_structures.py --- a/extra_tests/ctypes_tests/test_structures.py +++ b/extra_tests/ctypes_tests/test_structures.py @@ -190,3 +190,20 @@ assert sizeof(s) == 3 * sizeof(c_int) assert s.a == 4 # 256 + 4 assert s.b == -123 + +def test_memoryview(): + class S(Structure): + _fields_ = [('a', c_int16), + ('b', c_int16), + ] + + S3 = S * 3 + c_array = (2 * S3)( + S3(S(a=0, b=1), S(a=2, b=3), S(a=4, b=5)), + S3(S(a=6, b=7), S(a=8, b=9), S(a=10, b=11)), + ) + + mv = memoryview(c_array) + assert mv.format == 'T{<h:a:<h:b:}' + assert mv.shape == (2, 3) + assert mv.itemsize == 4 diff --git a/pypy/module/__pypy__/newmemoryview.py b/pypy/module/__pypy__/newmemoryview.py --- a/pypy/module/__pypy__/newmemoryview.py +++ b/pypy/module/__pypy__/newmemoryview.py @@ -6,33 +6,6 @@ from pypy.interpreter.gateway import unwrap_spec from pypy.objspace.std.memoryobject import BufferViewND -pep3118_size_map = { - # from struct documentation https://docs.python.org/3/library/struct.html - 'x': 1, #padding - '?': 1, - 'c': 1, - 'b': 1, - 'B': 1, - 'h': 2, - 'H': 2, - 'i': 4, - 'I': 4, - 'l': 4, - 'L': 4, - 'q': 8, - 'Q': 8, - 'e': 2, - 'f': 4, - 'd': 8, - # pep 3118 extensions - # https://www.python.org/dev/peps/pep-3118/#additions-to-the-struct-string-syntax - 'g': 16, # long double - is this platform dependent? - 'Zf': 8, - 'Zd':16, - 'Zg':32, - # Unhandled: 's', 'w' (UCS-4), 'c' (usc-1), 'u' (usc-2), 'O' (PyObject*), -} - @unwrap_spec(itemsize=int, format='text') def newmemoryview(space, w_obj, itemsize, format, w_shape=None, w_strides=None): ''' _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit