Author: Antonio Cuni <[email protected]>
Branch: faster-rstruct-2
Changeset: r91286:6c228d591ce8
Date: 2017-05-15 00:06 +0200
http://bitbucket.org/pypy/pypy/changeset/6c228d591ce8/
Log: we cannot use the fastpath for '<f' or '>f', because we need to
check for overflow in that case. It is fine to use the fastpath for
doubles though, because there is no risk of overflow
diff --git a/rpython/rlib/rstruct/standardfmttable.py
b/rpython/rlib/rstruct/standardfmttable.py
--- a/rpython/rlib/rstruct/standardfmttable.py
+++ b/rpython/rlib/rstruct/standardfmttable.py
@@ -106,7 +106,7 @@
size = rffi.sizeof(TYPE)
def packer(fmtiter):
fl = fmtiter.accept_float_arg()
- if pack_fastpath(TYPE)(fmtiter, fl):
+ if TYPE is not rffi.FLOAT and pack_fastpath(TYPE)(fmtiter, fl):
return
# slow path
try:
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
@@ -1,6 +1,7 @@
import pytest
from rpython.rlib.rarithmetic import r_ulonglong
from rpython.rlib.rstruct import standardfmttable, nativefmttable
+from rpython.rlib.rstruct.error import StructOverflowError
from rpython.rlib.mutbuffer import MutableStringBuffer
import struct
@@ -93,6 +94,14 @@
self.check('f', 123.456)
self.check('d', 123.456789)
+ def test_float_overflow(self):
+ if self.fmt_prefix == '@':
+ # native packing, no overflow
+ self.check('f', 10e100)
+ else:
+ # non-native packing, should raise
+ pytest.raises(StructOverflowError, "self.mypack('f', 10e100)")
+
def test_pack_char(self):
self.check('c', 'a')
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit