Author: Manuel Jacob <m...@manueljacob.de>
Branch: 
Changeset: r94003:f65cb735be28
Date: 2018-03-19 16:54 +0100
http://bitbucket.org/pypy/pypy/changeset/f65cb735be28/

Log:    Add 'e' (half-float) struct format to native format table. Copy
        CPython's behavior of using short's size and alignment for half-
        floats.

diff --git a/rpython/rlib/rstruct/nativefmttable.py 
b/rpython/rlib/rstruct/nativefmttable.py
--- a/rpython/rlib/rstruct/nativefmttable.py
+++ b/rpython/rlib/rstruct/nativefmttable.py
@@ -130,6 +130,13 @@
 sizeof_double = native_fmttable['d']['size']
 sizeof_float  = native_fmttable['f']['size']
 
+# Copy CPython's behavior of using short's size and alignment for half-floats.
+native_fmttable['e'] = {'size': native_fmttable['h']['size'],
+                        'alignment': native_fmttable['h']['alignment'],
+                        'pack': std.pack_halffloat,
+                        'unpack': std.unpack_halffloat,
+                       }
+
 # ____________________________________________________________
 #
 # A PyPy extension: accepts the 'u' format character in native mode,
diff --git a/rpython/rlib/rstruct/test/test_pack.py 
b/rpython/rlib/rstruct/test/test_pack.py
--- a/rpython/rlib/rstruct/test/test_pack.py
+++ b/rpython/rlib/rstruct/test/test_pack.py
@@ -139,9 +139,6 @@
         self.check('d', 123.456789)
 
     def test_pack_halffloat(self):
-        if self.fmttable is nativefmttable.native_fmttable:
-            # Host Python cannot handle half floats.
-            return
         size = 2
         wbuf = MutableStringBuffer(size)
         self.mypack_into('e', wbuf, 6.5e+04)
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to