[pypy-svn] r16439 - in pypy/dist/pypy: module/posix rpython rpython/module translator/c translator/c/src translator/c/test

tismer at codespeak.net tismer at codespeak.net
Thu Aug 25 00:08:10 CEST 2005


Author: tismer
Date: Thu Aug 25 00:08:05 2005
New Revision: 16439

Modified:
   pypy/dist/pypy/module/posix/__init__.py
   pypy/dist/pypy/module/posix/interp_posix.py
   pypy/dist/pypy/rpython/extfunctable.py
   pypy/dist/pypy/rpython/module/ll_os.py
   pypy/dist/pypy/translator/c/extfunc.py
   pypy/dist/pypy/translator/c/src/ll_os.h
   pypy/dist/pypy/translator/c/test/test_extfunc.py
Log:
added os.remove and os.unlink.
This was missing in order to run tests with the compiled pypy.

Also started to add the proper docstrings.
I'm not sure whether we should do this or fetch them
from the according CPython functions?

A remaining blocker that still hinders me from testing
is that the compiler seems to crash the compiled PyPy.
Try for instance the file test_complex.
If you put the whole big class into a triple quoted string ('''),
it at least tries to do something. Otherwise, the session
immediately crashes, whether interactive or not!


Modified: pypy/dist/pypy/module/posix/__init__.py
==============================================================================
--- pypy/dist/pypy/module/posix/__init__.py	(original)
+++ pypy/dist/pypy/module/posix/__init__.py	Thu Aug 25 00:08:05 2005
@@ -25,6 +25,8 @@
     'stat'      : 'interp_posix.stat',
     'dup'       : 'interp_posix.dup',
     'system'    : 'interp_posix.system',
+    'unlink'    : 'interp_posix.unlink',
+    'remove'    : 'interp_posix.remove',
     }
     if hasattr(os, 'ftruncate'):
         interpleveldefs['ftruncate'] = 'interp_posix.ftruncate'

Modified: pypy/dist/pypy/module/posix/interp_posix.py
==============================================================================
--- pypy/dist/pypy/module/posix/interp_posix.py	(original)
+++ pypy/dist/pypy/module/posix/interp_posix.py	Thu Aug 25 00:08:05 2005
@@ -118,6 +118,9 @@
 dup.unwrap_spec = [ObjSpace, int]
 
 def system(space, cmd):
+    """system(command) -> exit_status
+
+Execute the command (a string) in a subshell."""
     try:
         rc = os.system(cmd)
     except OSError, e: 
@@ -125,3 +128,23 @@
     else: 
         return space.wrap(rc)
 system.unwrap_spec = [ObjSpace, str]
+
+def unlink(space, path):
+    """unlink(path)
+
+Remove a file (same as remove(path))."""
+    try:
+        os.unlink(path)
+    except OSError, e: 
+        raise wrap_oserror(space, e) 
+unlink.unwrap_spec = [ObjSpace, str]
+
+def remove(space, path):
+    """remove(path)
+
+Remove a file (same as unlink(path))."""
+    try:
+        os.unlink(path)
+    except OSError, e: 
+        raise wrap_oserror(space, e) 
+remove.unwrap_spec = [ObjSpace, str]

Modified: pypy/dist/pypy/rpython/extfunctable.py
==============================================================================
--- pypy/dist/pypy/rpython/extfunctable.py	(original)
+++ pypy/dist/pypy/rpython/extfunctable.py	Thu Aug 25 00:08:05 2005
@@ -142,7 +142,8 @@
 declare(os.fstat    , statannotation, 'll_os/fstat')
 declare(os.stat     , statannotation, 'll_os/stat')
 declare(os.system   , int           , 'll_os/system')
-declare(os.strerror , str           , 'll_os/strerror')           
+declare(os.unlink   , noneannotation, 'll_os/unlink')
+declare(os.strerror , str           , 'll_os/strerror')
 declare(os.path.exists, bool        , 'll_os_path/exists')
 declare(os.path.isdir, bool         , 'll_os_path/isdir')
 declare(time.time   , float         , 'll_time/time')

Modified: pypy/dist/pypy/rpython/module/ll_os.py
==============================================================================
--- pypy/dist/pypy/rpython/module/ll_os.py	(original)
+++ pypy/dist/pypy/rpython/module/ll_os.py	Thu Aug 25 00:08:05 2005
@@ -117,3 +117,7 @@
 def ll_os_system(cmd):
     return os.system(from_rstr(cmd))
 ll_os_system.suggested_primitive = True
+
+def ll_os_unlink(path):
+    os.unlink(from_rstr(path))
+ll_os_unlink.suggested_primitive = True

Modified: pypy/dist/pypy/translator/c/extfunc.py
==============================================================================
--- pypy/dist/pypy/translator/c/extfunc.py	(original)
+++ pypy/dist/pypy/translator/c/extfunc.py	Thu Aug 25 00:08:05 2005
@@ -23,6 +23,7 @@
     ll_os  .ll_os_ftruncate:'LL_os_ftruncate',
     ll_os  .ll_os_strerror: 'LL_os_strerror',
     ll_os  .ll_os_system:  'LL_os_system',
+    ll_os  .ll_os_unlink:  'LL_os_unlink',
     ll_time.ll_time_clock: 'LL_time_clock',
     ll_time.ll_time_sleep: 'LL_time_sleep',
     ll_time.ll_time_time:  'LL_time_time',

Modified: pypy/dist/pypy/translator/c/src/ll_os.h
==============================================================================
--- pypy/dist/pypy/translator/c/src/ll_os.h	(original)
+++ pypy/dist/pypy/translator/c/src/ll_os.h	Thu Aug 25 00:08:05 2005
@@ -183,3 +183,10 @@
 long LL_os_system(RPyString * fname) {
   return system(RPyString_AsString(fname));
 }
+
+void LL_os_unlink(RPyString * fname) {
+  int error = unlink(RPyString_AsString(fname));
+  if (error != 0) {
+    RPYTHON_RAISE_OSERROR(errno);
+  }
+}

Modified: pypy/dist/pypy/translator/c/test/test_extfunc.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_extfunc.py	(original)
+++ pypy/dist/pypy/translator/c/test/test_extfunc.py	Thu Aug 25 00:08:05 2005
@@ -239,7 +239,7 @@
     f = compile(fmod1_0, [float])
     check(fmod1_0, f, 0.0)
 
-    
+
 def test_os_path_exists():
     tmpfile = str(udir.join('test_os_path_exists.TMP'))
     def fn():
@@ -389,3 +389,12 @@
     assert res is True
     res = f(1)
     assert res is False
+
+def test_os_unlink():
+    tmpfile = str(udir.join('test_os_path_exists.TMP'))
+    def fn():
+        os.unlink(tmpfile)
+    f = compile(fn, [])
+    open(tmpfile, 'w').close()
+    fn()
+    assert not os.path.exists(tmpfile)



More information about the Pypy-commit mailing list