[pypy-commit] pypy default: simplify

arigo noreply at buildbot.pypy.org
Tue May 26 00:36:34 CEST 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r77555:ac49c84ddcf2
Date: 2015-05-25 23:49 +0200
http://bitbucket.org/pypy/pypy/changeset/ac49c84ddcf2/

Log:	simplify

diff --git a/pypy/module/_cffi_backend/ctypeprim.py b/pypy/module/_cffi_backend/ctypeprim.py
--- a/pypy/module/_cffi_backend/ctypeprim.py
+++ b/pypy/module/_cffi_backend/ctypeprim.py
@@ -188,16 +188,7 @@
         if self.value_fits_long:
             value = misc.as_long(self.space, w_ob)
             if self.value_smaller_than_long:
-                size = self.size
-                if size == 1:
-                    signextended = misc.signext(value, 1)
-                elif size == 2:
-                    signextended = misc.signext(value, 2)
-                elif size == 4:
-                    signextended = misc.signext(value, 4)
-                else:
-                    raise AssertionError("unsupported size")
-                if value != signextended:
+                if value != misc.signext(value, self.size):
                     self._overflow(w_ob)
             misc.write_raw_signed_data(cdata, value, self.size)
         else:
diff --git a/pypy/module/_cffi_backend/misc.py b/pypy/module/_cffi_backend/misc.py
--- a/pypy/module/_cffi_backend/misc.py
+++ b/pypy/module/_cffi_backend/misc.py
@@ -216,10 +216,9 @@
 neg_msg = "can't convert negative number to unsigned"
 ovf_msg = "long too big to convert"
 
- at specialize.arg(1)
 def signext(value, size):
     # 'value' is sign-extended from 'size' bytes to a full integer.
-    # 'size' should be a constant smaller than a full integer size.
+    # 'size' should be smaller than a full integer size.
     if size == rffi.sizeof(rffi.SIGNEDCHAR):
         return rffi.cast(lltype.Signed, rffi.cast(rffi.SIGNEDCHAR, value))
     elif size == rffi.sizeof(rffi.SHORT):


More information about the pypy-commit mailing list