[pypy-commit] pypy ffistruct: rename space.truncatedint into truncatedint_w, and move the corresponding test to test_objspace

antocuni noreply at buildbot.pypy.org
Wed Nov 9 15:19:03 CET 2011


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: ffistruct
Changeset: r49017:e72220b3ba49
Date: 2011-11-09 14:05 +0100
http://bitbucket.org/pypy/pypy/changeset/e72220b3ba49/

Log:	rename space.truncatedint into truncatedint_w, and move the
	corresponding test to test_objspace

diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -1287,7 +1287,7 @@
                                  self.wrap("expected a 32-bit integer"))
         return value
 
-    def truncatedint(self, w_obj):
+    def truncatedint_w(self, w_obj):
         # Like space.gateway_int_w(), but return the integer truncated
         # instead of raising OverflowError.  For obscure cases only.
         try:
diff --git a/pypy/interpreter/gateway.py b/pypy/interpreter/gateway.py
--- a/pypy/interpreter/gateway.py
+++ b/pypy/interpreter/gateway.py
@@ -142,7 +142,7 @@
     def visit_c_nonnegint(self, el, app_sig):
         self.checked_space_method(el, app_sig)
 
-    def visit_truncatedint(self, el, app_sig):
+    def visit_truncatedint_w(self, el, app_sig):
         self.checked_space_method(el, app_sig)
 
     def visit__Wrappable(self, el, app_sig):
@@ -262,8 +262,8 @@
     def visit_c_nonnegint(self, typ):
         self.run_args.append("space.c_nonnegint_w(%s)" % (self.scopenext(),))
 
-    def visit_truncatedint(self, typ):
-        self.run_args.append("space.truncatedint(%s)" % (self.scopenext(),))
+    def visit_truncatedint_w(self, typ):
+        self.run_args.append("space.truncatedint_w(%s)" % (self.scopenext(),))
 
     def _make_unwrap_activation_class(self, unwrap_spec, cache={}):
         try:
@@ -395,8 +395,8 @@
     def visit_c_nonnegint(self, typ):
         self.unwrap.append("space.c_nonnegint_w(%s)" % (self.nextarg(),))
 
-    def visit_truncatedint(self, typ):
-        self.unwrap.append("space.truncatedint(%s)" % (self.nextarg(),))
+    def visit_truncatedint_w(self, typ):
+        self.unwrap.append("space.truncatedint_w(%s)" % (self.nextarg(),))
 
     def make_fastfunc(unwrap_spec, func):
         unwrap_info = UnwrapSpec_FastFunc_Unwrap()
diff --git a/pypy/interpreter/test/test_objspace.py b/pypy/interpreter/test/test_objspace.py
--- a/pypy/interpreter/test/test_objspace.py
+++ b/pypy/interpreter/test/test_objspace.py
@@ -213,6 +213,14 @@
         w_obj = space.wrap(-12)
         space.raises_w(space.w_ValueError, space.r_ulonglong_w, w_obj)
 
+    def test_truncatedint_w(self):
+        space = self.space
+        assert space.truncatedint_w(space.wrap(42)) == 42
+        assert space.truncatedint_w(space.wrap(sys.maxint)) == sys.maxint
+        assert space.truncatedint_w(space.wrap(sys.maxint+1)) == -sys.maxint-1
+        assert space.truncatedint_w(space.wrap(-1)) == -1
+        assert space.truncatedint_w(space.wrap(-sys.maxint-2)) == sys.maxint
+
     def test_truncatedlonglong_w(self):
         space = self.space
         w_value = space.wrap(12)
diff --git a/pypy/module/_ffi/interp_struct.py b/pypy/module/_ffi/interp_struct.py
--- a/pypy/module/_ffi/interp_struct.py
+++ b/pypy/module/_ffi/interp_struct.py
@@ -154,7 +154,7 @@
             return
         #
         if w_ffitype.is_signed() or w_ffitype.is_unsigned():
-            value = space.truncatedint(w_value)
+            value = space.truncatedint_w(w_value)
             libffi.struct_setfield_int(w_ffitype.ffitype, self.rawmem, offset, value)
             return
         #
diff --git a/pypy/module/_ffi/test/test_struct.py b/pypy/module/_ffi/test/test_struct.py
--- a/pypy/module/_ffi/test/test_struct.py
+++ b/pypy/module/_ffi/test/test_struct.py
@@ -38,16 +38,6 @@
         assert self.sizeof([T.slonglong, T.sbyte, T.sbyte, T.sbyte]) == llong_size + llong_align
         assert self.sizeof([T.slonglong, T.sbyte, T.sbyte, T.sbyte, T.sbyte]) == llong_size + llong_align
 
-    def test_truncatedint(self):
-        space = gettestobjspace()
-        assert space.truncatedint(space.wrap(42)) == 42
-        assert space.truncatedint(space.wrap(sys.maxint)) == sys.maxint
-        assert space.truncatedint(space.wrap(sys.maxint+1)) == -sys.maxint-1
-        assert space.truncatedint(space.wrap(-1)) == -1
-        assert space.truncatedint(space.wrap(-sys.maxint-2)) == sys.maxint
-
-
-
 class AppTestStruct(BaseAppTestFFI):
 
     def setup_class(cls):
diff --git a/pypy/module/binascii/interp_crc32.py b/pypy/module/binascii/interp_crc32.py
--- a/pypy/module/binascii/interp_crc32.py
+++ b/pypy/module/binascii/interp_crc32.py
@@ -61,7 +61,7 @@
 crc_32_tab = map(r_uint, crc_32_tab)
 
 
- at unwrap_spec(data='bufferstr', oldcrc='truncatedint')
+ at unwrap_spec(data='bufferstr', oldcrc='truncatedint_w')
 def crc32(space, data, oldcrc=0):
     "Compute the CRC-32 incrementally."
 
diff --git a/pypy/module/zlib/interp_zlib.py b/pypy/module/zlib/interp_zlib.py
--- a/pypy/module/zlib/interp_zlib.py
+++ b/pypy/module/zlib/interp_zlib.py
@@ -20,7 +20,7 @@
         return intmask((x ^ SIGN_EXTEND2) - SIGN_EXTEND2)
 
 
- at unwrap_spec(string='bufferstr', start='truncatedint')
+ at unwrap_spec(string='bufferstr', start='truncatedint_w')
 def crc32(space, string, start = rzlib.CRC32_DEFAULT_START):
     """
     crc32(string[, start]) -- Compute a CRC-32 checksum of string.
@@ -41,7 +41,7 @@
     return space.wrap(checksum)
 
 
- at unwrap_spec(string='bufferstr', start='truncatedint')
+ at unwrap_spec(string='bufferstr', start='truncatedint_w')
 def adler32(space, string, start=rzlib.ADLER32_DEFAULT_START):
     """
     adler32(string[, start]) -- Compute an Adler-32 checksum of string.


More information about the pypy-commit mailing list