Author: Brian Kearns <bdkea...@gmail.com>
Branch: 
Changeset: r73320:14a5e9603b7a
Date: 2014-09-05 13:35 -0400
http://bitbucket.org/pypy/pypy/changeset/14a5e9603b7a/

Log:    support IOError in rpython

diff --git a/rpython/annotator/builtin.py b/rpython/annotator/builtin.py
--- a/rpython/annotator/builtin.py
+++ b/rpython/annotator/builtin.py
@@ -255,6 +255,10 @@
         BUILTIN_ANALYZERS[original] = value
 
 
+@analyzer_for(getattr(IOError.__init__, 'im_func', IOError.__init__))
+def IOError_init(s_self, *args):
+    pass
+
 @analyzer_for(getattr(OSError.__init__, 'im_func', OSError.__init__))
 def OSError_init(s_self, *args):
     pass
diff --git a/rpython/annotator/classdef.py b/rpython/annotator/classdef.py
--- a/rpython/annotator/classdef.py
+++ b/rpython/annotator/classdef.py
@@ -438,8 +438,9 @@
 # ____________________________________________________________
 
 FORCE_ATTRIBUTES_INTO_CLASSES = {
+    IOError: {'errno': SomeInteger()},
     OSError: {'errno': SomeInteger()},
-    }
+}
 
 try:
     WindowsError
diff --git a/rpython/rtyper/rbuiltin.py b/rpython/rtyper/rbuiltin.py
--- a/rpython/rtyper/rbuiltin.py
+++ b/rpython/rtyper/rbuiltin.py
@@ -264,6 +264,17 @@
 def rtype_object__init__(hop):
     hop.exception_cannot_occur()
 
+def rtype_IOError__init__(hop):
+    hop.exception_cannot_occur()
+    if hop.nb_args == 2:
+        raise TyperError("IOError() should not be called with "
+                         "a single argument")
+    if hop.nb_args >= 3:
+        v_self = hop.args_v[0]
+        r_self = hop.args_r[0]
+        v_errno = hop.inputarg(lltype.Signed, arg=1)
+        r_self.setfield(v_self, 'errno', v_errno, hop.llops)
+
 def rtype_OSError__init__(hop):
     hop.exception_cannot_occur()
     if hop.nb_args == 2:
@@ -333,6 +344,9 @@
         original = getattr(__builtin__, name[14:])
         BUILTIN_TYPER[original] = value
 
+BUILTIN_TYPER[getattr(IOError.__init__, 'im_func', IOError.__init__)] = (
+    rtype_IOError__init__)
+
 BUILTIN_TYPER[getattr(OSError.__init__, 'im_func', OSError.__init__)] = (
     rtype_OSError__init__)
 
diff --git a/rpython/rtyper/test/test_exception.py 
b/rpython/rtyper/test/test_exception.py
--- a/rpython/rtyper/test/test_exception.py
+++ b/rpython/rtyper/test/test_exception.py
@@ -36,14 +36,23 @@
 class TestException(BaseRtypingTest):
     def test_exception_with_arg(self):
         def g(n):
+            raise IOError(n, "?")
+        def h(n):
             raise OSError(n, "?")
         def f(n):
             try:
                 g(n)
+            except IOError, e:
+                assert e.errno == 42
+            else:
+                assert False
+            try:
+                h(n)
             except OSError, e:
-                return e.errno
-        res = self.interpret(f, [42])
-        assert res == 42
+                assert e.errno == 42
+            else:
+                assert False
+        self.interpret(f, [42])
 
     def test_catch_incompatible_class(self):
         class MyError(Exception):
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to