[pypy-commit] lang-smalltalk default: fixed the JIT-bug:

lwassermann noreply at buildbot.pypy.org
Tue Jun 18 16:04:25 CEST 2013


Author: Lars Wassermann <lars.wassermann at gmail.com>
Branch: 
Changeset: r463:52d5e8f2ef2d
Date: 2013-06-18 15:57 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/52d5e8f2ef2d/

Log:	fixed the JIT-bug: wrap_int was annotated with longlong
	type, although it should have been int fixed all such send
	sites added assert to ensure proper errors on future
	mistakes added try:except: block in fileplugin, to be able
	to run the vm in the meta-interpreter

diff --git a/spyvm/objspace.py b/spyvm/objspace.py
--- a/spyvm/objspace.py
+++ b/spyvm/objspace.py
@@ -199,6 +199,7 @@
 
     def wrap_int(self, val):
         from spyvm import constants
+        assert isinstance(val, int)
         if int_between(constants.TAGGED_MININT, val,
                         constants.TAGGED_MAXINT + 1):
             return model.W_SmallInteger(val)
diff --git a/spyvm/plugins/fileplugin.py b/spyvm/plugins/fileplugin.py
--- a/spyvm/plugins/fileplugin.py
+++ b/spyvm/plugins/fileplugin.py
@@ -1,19 +1,21 @@
 import os, stat, sys
 
-from rpython.rlib import jit
+from rpython.rlib import jit, rarithmetic
 from rpython.rlib.listsort import TimSort
 
 from spyvm import model, error
 from spyvm.plugins.plugin import Plugin
 from spyvm.primitives import PrimitiveFailedError, index1_0
 
-
 FilePlugin = Plugin()
 os.stat_float_times(False)
 
-std_fds = [sys.stdin.fileno(),
+try:
+    std_fds = [sys.stdin.fileno(),
            sys.stdout.fileno(),
            sys.stderr.fileno()]
+except ValueError:
+    std_fds = [0, 1, 2]
 
 @FilePlugin.expose_primitive(unwrap_spec=[object])
 def primitiveDirectoryDelimitor(interp, s_frame, w_rcvr):
@@ -44,7 +46,7 @@
     w_creationTime = smalltalk_timestamp(space, file_info.st_ctime)
     w_modificationTime = smalltalk_timestamp(space, file_info.st_mtime)
     w_dirFlag = space.w_true if stat.S_IFDIR & file_info.st_mode else space.w_false
-    w_fileSize = space.wrap_int(file_info.st_size)
+    w_fileSize = space.wrap_int(rarithmetic.intmask(file_info.st_size))
 
     return space.wrap_list([w_name, w_creationTime, w_modificationTime,
                             w_dirFlag, w_fileSize])
@@ -70,7 +72,6 @@
 
 @FilePlugin.expose_primitive(unwrap_spec=[object, int])
 def primitiveFileClose(interp, s_frame, w_rcvr, fd):
-    from rpython.rlib.rarithmetic import intmask
     try:
         os.close(fd)
     except OSError:
@@ -108,7 +109,7 @@
     except OSError:
         raise PrimitiveFailedError
     else:
-        return interp.space.wrap_int(pos)
+        return interp.space.wrap_positive_32bit_int(rarithmetic.intmask(pos))
 
 @FilePlugin.expose_primitive(unwrap_spec=[object, int, int])
 def primitiveFileSetPosition(interp, s_frame, w_rcvr, fd, position):
@@ -124,7 +125,7 @@
         file_info = os.fstat(fd)
     except OSError:
         raise PrimitiveFailedError
-    return interp.space.wrap_int(file_info.st_size)
+    return interp.space.wrap_positive_32bit_int(rarithmetic.intmask(file_info.st_size))
 
 @FilePlugin.expose_primitive(unwrap_spec=[object])
 def primitiveFileStdioHandles(interp, s_frame, w_rcvr):
diff --git a/spyvm/test/test_objectspace.py b/spyvm/test/test_objectspace.py
--- a/spyvm/test/test_objectspace.py
+++ b/spyvm/test/test_objectspace.py
@@ -55,5 +55,17 @@
     # byteobj.bytes.append('\x01')
     # num = space.unwrap_uint(byteobj)
     # should not raise. see docstring.
-  
 
+
+def test_wrap_int():
+    for num in [-10, 1, 15, 0x3fffffff]:
+        assert space.wrap_int(num).value == num
+
+    for num in [2L, -5L]:
+        with py.test.raises(AssertionError):
+            space.wrap_int(num)
+
+    from rpython.rlib.rarithmetic import intmask
+    for num in [0x7fffffff, intmask(0x80000000)]:
+        with py.test.raises(objspace.WrappingError):
+            space.wrap_int(num)


More information about the pypy-commit mailing list