Blame python-numpy-stl-be.patch

c1a25e4
From 33c00d095b5bf1055e32de783d34104829393464 Mon Sep 17 00:00:00 2001
c1a25e4
From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= <miro@hroncok.cz>
c1a25e4
Date: Fri, 30 Dec 2016 16:11:26 +0100
c1a25e4
Subject: [PATCH] Always use little endian when loading/saving binary STLs
c1a25e4
c1a25e4
This is neccessary to make this work on big endian architectures,
c1a25e4
up until now the saving and loading was arch specific.
c1a25e4
c1a25e4
Binary STLs saved as little endian (most of the existing STLs)
c1a25e4
where not compatible with numpy-stl running on big endian system.
c1a25e4
c1a25e4
Fixes https://github.com/WoLpH/numpy-stl/issues/43
c1a25e4
---
c1a25e4
 stl/base.py             | 1 +
c1a25e4
 stl/stl.py              | 4 ++--
c1a25e4
 tests/stl_corruption.py | 2 +-
c1a25e4
 3 files changed, 4 insertions(+), 3 deletions(-)
c1a25e4
c1a25e4
diff --git a/stl/base.py b/stl/base.py
c1a25e4
index b322d8b..c5ea28c 100644
c1a25e4
--- a/stl/base.py
c1a25e4
+++ b/stl/base.py
c1a25e4
@@ -145,6 +145,7 @@ class BaseMesh(logger.Logged, collections.Mapping):
c1a25e4
         (s('vectors'), numpy.float32, (3, 3)),
c1a25e4
         (s('attr'), numpy.uint16, (1, )),
c1a25e4
     ])
c1a25e4
+    dtype = dtype.newbyteorder('<')  # Even on big endian arches, use little e.
c1a25e4
 
c1a25e4
     def __init__(self, data, calculate_normals=True,
c1a25e4
                  remove_empty_areas=False,
c1a25e4
diff --git a/stl/stl.py b/stl/stl.py
c1a25e4
index c438a95..b4753a6 100644
c1a25e4
--- a/stl/stl.py
c1a25e4
+++ b/stl/stl.py
c1a25e4
@@ -97,7 +97,7 @@ def _load_binary(cls, fh, header, check_size=False):
c1a25e4
         if len(count_data) != COUNT_SIZE:
c1a25e4
             count = 0
c1a25e4
         else:
c1a25e4
-            count, = struct.unpack(s('@i'), b(count_data))
c1a25e4
+            count, = struct.unpack(s('
c1a25e4
         # raise RuntimeError()
c1a25e4
         assert count < MAX_COUNT, ('File too large, got %d triangles which '
c1a25e4
                                    'exceeds the maximum of %d') % (
c1a25e4
@@ -286,7 +286,7 @@ def _write_binary(self, fh, name):
c1a25e4
 
c1a25e4
         # Make it exactly 80 characters
c1a25e4
         header = header[:80].ljust(80, ' ')
c1a25e4
-        packed = struct.pack(s('@i'), self.data.size)
c1a25e4
+        packed = struct.pack(s('
c1a25e4
 
c1a25e4
         if isinstance(fh, io.TextIOWrapper):  # pragma: no cover
c1a25e4
             packed = str(packed)
c1a25e4
diff --git a/tests/stl_corruption.py b/tests/stl_corruption.py
c1a25e4
index 405b9c6..aa6f5e8 100644
c1a25e4
--- a/tests/stl_corruption.py
c1a25e4
+++ b/tests/stl_corruption.py
c1a25e4
@@ -99,7 +99,7 @@ def test_corrupt_ascii_file(tmpdir, speedups):
c1a25e4
         fh.seek(40)
c1a25e4
         print(' ' * 100, file=fh)
c1a25e4
         fh.seek(80)
c1a25e4
-        fh.write(struct.pack('@i', 10).decode('utf-8'))
c1a25e4
+        fh.write(struct.pack('
c1a25e4
         fh.seek(0)
c1a25e4
         with pytest.raises(AssertionError):
c1a25e4
             mesh.Mesh.from_file(str(tmp_file), fh=fh, speedups=speedups)