[pypy-svn] r45730 - 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:32:52 CEST 2007


Author: arigo
Date: Thu Aug 16 16:32:52 2007
New Revision: 45730

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.link()...
os.symlink()...


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:32:52 2007
@@ -151,10 +151,6 @@
 # external function declarations
 posix = __import__(os.name)
 declare(os._exit    , noneannotation, 'll_os/_exit')
-if hasattr(os, 'link'):
-    declare(os.link     , noneannotation, 'll_os/link')
-if hasattr(os, 'symlink'):
-    declare(os.symlink  , noneannotation, 'll_os/symlink')
 if hasattr(os, 'fork'):
     declare(os.fork ,     int,            'll_os/fork')
 if hasattr(os, 'spawnv'):

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:32:52 2007
@@ -788,6 +788,45 @@
             self.register(os.kill, [int, int], s_None, llimpl=kill_lltypeimpl,
                           export_name="ll_os.ll_os_kill")
 
+    if hasattr(os, 'link'):
+        @registering(os.link)
+        def register_os_link(self):
+            os_link = rffi.llexternal('link', [rffi.CCHARP, rffi.CCHARP],
+                                      rffi.INT,
+                                      includes = ['unistd.h'])
+
+            def link_lltypeimpl(oldpath, newpath):
+                l_oldpath = rffi.str2charp(oldpath)
+                l_newpath = rffi.str2charp(newpath)
+                res = os_link(l_oldpath, l_newpath)
+                rffi.free_charp(l_newpath)
+                rffi.free_charp(l_oldpath)
+                if res < 0:
+                    raise OSError(rffi.get_errno(), "os_link failed")
+
+            self.register(os.link, [str, str], s_None, llimpl=link_lltypeimpl,
+                          export_name="ll_os.ll_os_link")
+
+    if hasattr(os, 'symlink'):
+        @registering(os.symlink)
+        def register_os_symlink(self):
+            os_symlink = rffi.llexternal('symlink', [rffi.CCHARP, rffi.CCHARP],
+                                         rffi.INT,
+                                         includes = ['unistd.h'])
+
+            def symlink_lltypeimpl(oldpath, newpath):
+                l_oldpath = rffi.str2charp(oldpath)
+                l_newpath = rffi.str2charp(newpath)
+                res = os_symlink(l_oldpath, l_newpath)
+                rffi.free_charp(l_newpath)
+                rffi.free_charp(l_oldpath)
+                if res < 0:
+                    raise OSError(rffi.get_errno(), "os_symlink failed")
+
+            self.register(os.symlink, [str, str], s_None,
+                          llimpl=symlink_lltypeimpl,
+                          export_name="ll_os.ll_os_symlink")
+
 # --------------------------- os.stat & variants ---------------------------
 
     @registering(os.fstat)
@@ -877,14 +916,6 @@
     # XXX deprecated style, this is all waiting to be converted to rffi
     __metaclass__ = ClassMethods
 
-    def ll_os_link(cls, path1, path2):
-        os.link(cls.from_rstr(path1), cls.from_rstr(path2))
-    ll_os_link.suggested_primitive = True
-
-    def ll_os_symlink(cls, path1, path2):
-        os.symlink(cls.from_rstr(path1), cls.from_rstr(path2))
-    ll_os_symlink.suggested_primitive = True
-
     def ll_os_fork(cls):
         return os.fork()
     ll_os_fork.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:32:52 2007
@@ -20,8 +20,6 @@
 # references to functions, so we cannot insert classmethods here.
 
 EXTERNALS = {
-    impl.ll_os_link.im_func:    'LL_os_link',
-    impl.ll_os_symlink.im_func: 'LL_os_symlink',
     impl.ll_os_fork.im_func:    'LL_os_fork',
     impl.ll_os_spawnv.im_func:  'LL_os_spawnv',
     impl.ll_os__exit.im_func:   'LL_os__exit',

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:32:52 2007
@@ -22,34 +22,11 @@
 #endif
 #endif /* MAXPATHLEN */
 
-/* The functions below are mapped to functions from pypy.rpython.module.*
-   by the pypy.translator.c.extfunc.EXTERNALS dictionary.
-   They should correspond to the functions with the suggested_primitive
-   flag set, and NOT necessarily directly to the ll_os_*() functions.
-   See for example ll_read_into(), which is called by ll_os_read().
-   The latter would be messy to write here, but LL_read_into() is quite easy.
+/* NOTE NOTE NOTE: This whole file is going away...
 */
 
-
-#if !(defined(MS_WIN64) || defined(MS_WINDOWS))
-#       define HAVE_FILESYSTEM_WITH_LINKS
-#endif
-
-
 /* prototypes */
 
-int LL_os_isatty(long fd);
-long LL_os_system(RPyString * fname);
-void LL_os_unlink(RPyString * fname);
-void LL_os_chdir(RPyString * path);
-void LL_os_mkdir(RPyString * path, int mode);
-void LL_os_rmdir(RPyString * path);
-void LL_os_chmod(RPyString * path, int mode);
-void LL_os_rename(RPyString * path1, RPyString * path2);
-int LL_os_umask(int mode);
-void LL_os_kill(int pid, int sig);
-void LL_os_link(RPyString * path1, RPyString * path2);
-void LL_os_symlink(RPyString * path1, RPyString * path2);
 long LL_os_fork(void);
 #if defined(HAVE_SPAWNV) && defined(HAVE_RPY_LIST_OF_STRING) /* argh */
 long LL_os_spawnv(int mode, RPyString *path, RPyListOfString *args);
@@ -68,23 +45,6 @@
 
 #include "ll_osdefs.h"
 
-#ifdef HAVE_FILESYSTEM_WITH_LINKS
-
-void LL_os_link(RPyString * path1, RPyString * path2) {
-    int error = link(RPyString_AsString(path1), RPyString_AsString(path2));
-    if (error != 0) {
-	RPYTHON_RAISE_OSERROR(errno);
-    }
-}
-
-void LL_os_symlink(RPyString * path1, RPyString * path2) {
-    int error = symlink(RPyString_AsString(path1), RPyString_AsString(path2));
-    if (error != 0) {
-	RPYTHON_RAISE_OSERROR(errno);
-    }
-}
-#endif
-
 #ifdef HAVE_FORK
 long LL_os_fork(void) {
 	int pid = fork();



More information about the Pypy-commit mailing list