Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r68417:ca66d486e64d
Date: 2013-12-13 08:50 +0100
http://bitbucket.org/pypy/pypy/changeset/ca66d486e64d/

Log:    Support os.remove() in RPython. It worked accidentally when the
        translator was running on CPython, but not on PyPy, due to
        'os.remove == os.unlink' being false.

diff --git a/rpython/flowspace/specialcase.py b/rpython/flowspace/specialcase.py
--- a/rpython/flowspace/specialcase.py
+++ b/rpython/flowspace/specialcase.py
@@ -54,6 +54,12 @@
     from rpython.rlib.rfile import create_temp_rfile
     return space.appcall(create_temp_rfile)
 
+@register_flow_sc(os.remove)
+def sc_os_remove(space, *args_w):
+    # on top of PyPy only: 'os.remove != os.unlink'
+    # (on CPython they are '==', but not identical either)
+    return space.appcall(os.unlink, *args_w)
+
 # _________________________________________________________________________
 # a simplified version of the basic printing routines, for RPython programs
 class StdOutBuffer:
diff --git a/rpython/flowspace/test/test_objspace.py 
b/rpython/flowspace/test/test_objspace.py
--- a/rpython/flowspace/test/test_objspace.py
+++ b/rpython/flowspace/test/test_objspace.py
@@ -1244,6 +1244,20 @@
             graph = self.codetest(g)
         assert "Undefined closure variable 'b'" in str(excinfo.value)
 
+    def call_os_remove(msg):
+        os.remove(msg)
+        os.unlink(msg)
+
+    def test_call_os_remove(self):
+        x = self.codetest(self.call_os_remove)
+        simplify_graph(x)
+        self.show(x)
+        ops = x.startblock.operations
+        assert ops[0].opname == 'simple_call'
+        assert ops[0].args[0].value is os.unlink
+        assert ops[1].opname == 'simple_call'
+        assert ops[1].args[0].value is os.unlink
+
 
 DATA = {'x': 5,
         'y': 6}
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to