Author: Brian Kearns <bdkea...@gmail.com>
Branch: 
Changeset: r69009:0ba3660ac64a
Date: 2014-01-29 18:24 -0500
http://bitbucket.org/pypy/pypy/changeset/0ba3660ac64a/

Log:    merge heads

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
@@ -142,7 +142,7 @@
             pack = std.pack_bool
             unpack = std.unpack_bool
         else:
-            pack = std.make_int_packer(size, signed, True)
+            pack = std.make_int_packer(size, signed)
             unpack = std.make_int_unpacker(size, signed)
 
         native_fmttable[fmtchar] = {'size': size,
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
@@ -13,13 +13,6 @@
 from rpython.rlib.rstruct.error import StructError, StructOverflowError
 from rpython.rlib.unroll import unrolling_iterable
 
-# In the CPython struct module, pack() unconsistently accepts inputs
-# that are out-of-range or floats instead of ints.  Should we emulate
-# this?  Let's use a flag for now:
-
-PACK_ACCEPTS_BROKEN_INPUT = True
-
-# ____________________________________________________________
 
 def pack_pad(fmtiter, count):
     fmtiter.result.append_multiple_char('\x00', count)
@@ -99,12 +92,8 @@
             max = r_ulonglong(max)
     return min, max, accept_method
 
-def make_int_packer(size, signed, cpython_checks_range, _memo={}):
-    if cpython_checks_range:
-        check_range = True
-    else:
-        check_range = not PACK_ACCEPTS_BROKEN_INPUT
-    key = (size, signed, check_range)
+def make_int_packer(size, signed, _memo={}):
+    key = size, signed
     try:
         return _memo[key]
     except KeyError:
@@ -121,9 +110,8 @@
     def pack_int(fmtiter):
         method = getattr(fmtiter, accept_method)
         value = method()
-        if check_range:
-            if value < min or value > max:
-                raise StructError(errormsg)
+        if not min <= value <= max:
+            raise StructError(errormsg)
         if fmtiter.bigendian:
             for i in unroll_revrange_size:
                 x = (value >> (8*i)) & 0xff
@@ -237,8 +225,8 @@
 
 for c, size in [('b', 1), ('h', 2), ('i', 4), ('l', 4), ('q', 8)]:
     standard_fmttable[c] = {'size': size,
-                            'pack': make_int_packer(size, True, True),
+                            'pack': make_int_packer(size, True),
                             'unpack': make_int_unpacker(size, True)}
     standard_fmttable[c.upper()] = {'size': size,
-                                    'pack': make_int_packer(size, False, True),
+                                    'pack': make_int_packer(size, False),
                                     'unpack': make_int_unpacker(size, False)}
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to