[pypy-svn] r45725 - in pypy/branch/pypy-more-rtti-inprogress: rpython rpython/module translator/c translator/c/src

arigo at codespeak.net arigo at codespeak.net
Thu Aug 16 16:15:02 CEST 2007


Author: arigo
Date: Thu Aug 16 16:15:01 2007
New Revision: 45725

Modified:
   pypy/branch/pypy-more-rtti-inprogress/rpython/extfunctable.py
   pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_os.py
   pypy/branch/pypy-more-rtti-inprogress/translator/c/extfunc.py
   pypy/branch/pypy-more-rtti-inprogress/translator/c/src/ll_os.h
Log:
os.chdir()...
os.mkdir()...
os.rmdir()...


Modified: pypy/branch/pypy-more-rtti-inprogress/rpython/extfunctable.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/rpython/extfunctable.py	(original)
+++ pypy/branch/pypy-more-rtti-inprogress/rpython/extfunctable.py	Thu Aug 16 16:15:01 2007
@@ -150,9 +150,6 @@
 
 # external function declarations
 posix = __import__(os.name)
-declare(os.chdir    , noneannotation, 'll_os/chdir')
-declare(os.mkdir    , noneannotation, 'll_os/mkdir')
-declare(os.rmdir    , noneannotation, 'll_os/rmdir')
 if hasattr(posix, 'unsetenv'):   # note: faked in os
     declare(os.unsetenv , noneannotation, 'll_os/unsetenv')
 declare(os.chmod    , noneannotation, 'll_os/chmod')

Modified: pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_os.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_os.py	(original)
+++ pypy/branch/pypy-more-rtti-inprogress/rpython/module/ll_os.py	Thu Aug 16 16:15:01 2007
@@ -656,6 +656,69 @@
         self.register(os.unlink, [str], s_None, llimpl=unlink_lltypeimpl,
                       export_name="ll_os.ll_os_unlink")
 
+    @registering(os.chdir)
+    def register_os_chdir(self):
+        if sys.platform.startswith('win'):
+            INCLUDES = []
+        else:
+            INCLUDES = ['unistd.h']
+        os_chdir = rffi.llexternal('chdir', [rffi.CCHARP], rffi.INT,
+                                   includes=INCLUDES)
+
+        def chdir_lltypeimpl(path):
+            l_path = rffi.str2charp(path)
+            res = os_chdir(l_path)
+            rffi.free_charp(l_path)
+            if res < 0:
+                raise OSError(rffi.get_errno(), "os_chdir failed")
+
+        self.register(os.chdir, [str], s_None, llimpl=chdir_lltypeimpl,
+                      export_name="ll_os.ll_os_chdir")
+
+    @registering(os.mkdir)
+    def register_os_mkdir(self):
+        if os.name == 'nt':
+            INCLUDES = []
+            ARG2 = []         # no 'mode' argument on Windows
+            arg2 = []
+        else:
+            INCLUDES = ['sys/stat.h', 'sys/types.h']
+            ARG2 = [rffi.MODE_T]
+            arg2 = [int]
+        os_mkdir = rffi.llexternal('mkdir', [rffi.CCHARP]+ARG2, rffi.INT,
+                                   includes=INCLUDES)
+
+        def mkdir_lltypeimpl(pathname, *opt_mode):
+            l_pathname = rffi.str2charp(pathname)
+            if opt_mode:
+                opt_mode = (rffi.cast(rffi.MODE_T, opt_mode[0]),)
+            res = os_mkdir(l_pathname, *opt_mode)
+            rffi.free_charp(l_pathname)
+            if res < 0:
+                raise OSError(rffi.get_errno(), "os_mkdir failed")
+
+        self.register(os.mkdir, [str]+arg2, s_None, llimpl=mkdir_lltypeimpl,
+                      export_name="ll_os.ll_os_mkdir")
+
+    @registering(os.rmdir)
+    def register_os_rmdir(self):
+        if sys.platform.startswith('win'):
+            INCLUDES = []
+        else:
+            INCLUDES = ['unistd.h']
+        os_rmdir = rffi.llexternal('rmdir', [rffi.CCHARP], rffi.INT,
+                                   includes=INCLUDES)
+
+        def rmdir_lltypeimpl(pathname):
+            l_pathname = rffi.str2charp(pathname)
+            res = os_rmdir(l_pathname)
+            rffi.free_charp(l_pathname)
+            if res < 0:
+                raise OSError(rffi.get_errno(), "os_rmdir failed")
+
+        self.register(os.rmdir, [str], s_None, llimpl=rmdir_lltypeimpl,
+                      export_name="ll_os.ll_os_rmdir")
+
 # --------------------------- os.stat & variants ---------------------------
 
     @registering(os.fstat)
@@ -745,18 +808,6 @@
     # XXX deprecated style, this is all waiting to be converted to rffi
     __metaclass__ = ClassMethods
 
-    def ll_os_chdir(cls, path):
-        os.chdir(cls.from_rstr(path))
-    ll_os_chdir.suggested_primitive = True
-
-    def ll_os_mkdir(cls, path, mode):
-        os.mkdir(cls.from_rstr(path), mode)
-    ll_os_mkdir.suggested_primitive = True
-
-    def ll_os_rmdir(cls, path):
-        os.rmdir(cls.from_rstr(path))
-    ll_os_rmdir.suggested_primitive = True
-
     def ll_os_chmod(cls, path, mode):
         os.chmod(cls.from_rstr(path), mode)
     ll_os_chmod.suggested_primitive = True

Modified: pypy/branch/pypy-more-rtti-inprogress/translator/c/extfunc.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/translator/c/extfunc.py	(original)
+++ pypy/branch/pypy-more-rtti-inprogress/translator/c/extfunc.py	Thu Aug 16 16:15:01 2007
@@ -20,9 +20,6 @@
 # references to functions, so we cannot insert classmethods here.
 
 EXTERNALS = {
-    impl.ll_os_chdir.im_func:   'LL_os_chdir',
-    impl.ll_os_mkdir.im_func:   'LL_os_mkdir',
-    impl.ll_os_rmdir.im_func:   'LL_os_rmdir',
     impl.ll_os_chmod.im_func:   'LL_os_chmod',
     impl.ll_os_rename.im_func:  'LL_os_rename',
     impl.ll_os_umask.im_func:   'LL_os_umask',

Modified: pypy/branch/pypy-more-rtti-inprogress/translator/c/src/ll_os.h
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/translator/c/src/ll_os.h	(original)
+++ pypy/branch/pypy-more-rtti-inprogress/translator/c/src/ll_os.h	Thu Aug 16 16:15:01 2007
@@ -68,32 +68,6 @@
 
 #include "ll_osdefs.h"
 
-void LL_os_chdir(RPyString * path) {
-    int error = chdir(RPyString_AsString(path));
-    if (error != 0) {
-	RPYTHON_RAISE_OSERROR(errno);
-    }
-}
-
-void LL_os_mkdir(RPyString * path, int mode) {
-#if defined(MS_WIN64) || defined(MS_WINDOWS)
-    /* no mode support on Windows */
-    int error = mkdir(RPyString_AsString(path));
-#else
-    int error = mkdir(RPyString_AsString(path), mode);
-#endif
-    if (error != 0) {
-	RPYTHON_RAISE_OSERROR(errno);
-    }
-}
-
-void LL_os_rmdir(RPyString * path) {
-    int error = rmdir(RPyString_AsString(path));
-    if (error != 0) {
-	RPYTHON_RAISE_OSERROR(errno);
-    }
-}
-
 void LL_os_chmod(RPyString * path, int mode) {
     int error = chmod(RPyString_AsString(path), mode);
     if (error != 0) {



More information about the Pypy-commit mailing list