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

fijal at codespeak.net fijal at codespeak.net
Fri Dec 1 10:49:46 CET 2006


Author: fijal
Date: Fri Dec  1 10:49:43 2006
New Revision: 35190

Modified:
   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.execv


Modified: pypy/dist/pypy/rpython/extfunctable.py
==============================================================================
--- pypy/dist/pypy/rpython/extfunctable.py	(original)
+++ pypy/dist/pypy/rpython/extfunctable.py	Fri Dec  1 10:49:43 2006
@@ -233,6 +233,8 @@
     declare(os.spawnv,    int,            'll_os/spawnv')
 if hasattr(os, 'waitpid'):
     declare(os.waitpid ,  waitpidannotation, 'll_os/waitpid')
+if hasattr(os, 'execv'):
+    declare(os.execv, noneannotation, 'll_os/execv')
 
 declare(os.path.exists, bool        , 'll_os_path/exists')
 declare(os.path.isdir, bool         , 'll_os_path/isdir')

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	Fri Dec  1 10:49:43 2006
@@ -96,6 +96,10 @@
         return os.system(cls.from_rstr(cmd))
     ll_os_system.suggested_primitive = True
 
+    def ll_os_execv(cls, cmd, args):
+        os.execv(cmd, args)
+    ll_os_execv.suggested_primitive = True
+
     def ll_os_unlink(cls, path):
         os.unlink(cls.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	Fri Dec  1 10:49:43 2006
@@ -60,6 +60,7 @@
     impl.ll_os_spawnv.im_func:  'LL_os_spawnv',
     impl.ll_os_waitpid.im_func: 'LL_os_waitpid',
     impl.ll_os__exit.im_func:   'LL_os__exit',
+    impl.ll_os_execv.im_func:   'LL_os_execv',
     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	Fri Dec  1 10:49:43 2006
@@ -80,6 +80,7 @@
 long LL_readlink_into(RPyString *path, RPyString *buffer);
 long LL_os_fork(void);
 #ifdef HAVE_RPY_LIST_OF_STRING     /* argh */
+void LL_os_execv(RPyString *cmd, RPyListOfString *args);
 long LL_os_spawnv(int mode, RPyString *path, RPyListOfString *args);
 #endif
 RPyWAITPID_RESULT* LL_os_waitpid(long pid, long options);
@@ -389,6 +390,20 @@
 }
 #endif
 
+#if defined(HAVE_EXECV) && defined(HAVE_RPY_LIST_OF_STRING)
+void LL_os_execv(RPyString *cmd, RPyListOfString *args) {
+	int i, nargs = args->l_length;
+  char **slist = malloc((nargs+1) * sizeof(char*));
+	if (slist) {
+		for (i=0; i<nargs; i++)
+			slist[i] = RPyString_AsString(args->l_items->items[i]);
+		slist[nargs] = NULL;
+    execv(RPyString_AsString(cmd), slist);
+  } /* should never return */
+  RPYTHON_RAISE_OSERROR(errno);
+}
+#endif
+
 /*
   The following code is only generated if spawnv exists and
   if RPyListOfString exists. The latter is a bit tricky:

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	Fri Dec  1 10:49:43 2006
@@ -5,6 +5,7 @@
 from pypy.translator.c.test.test_genc import compile
 from pypy.translator.c.extfunc import EXTERNALS
 from pypy.rlib import ros
+from pypy.translator.stackless.test.test_transform import one
 
 def test_all_suggested_primitives():
     for modulename in ['ll_math', 'll_os', 'll_os_path', 'll_time']:
@@ -684,3 +685,20 @@
     compared_with.sort()
     assert result == compared_with
 
+if hasattr(posix, 'execv'):
+    def test_execv():
+        filename = str(udir.join('test_execv.txt'))
+        def does_stuff():
+            progname = str(sys.executable)
+            l = []
+            l.append(progname)
+            l += ["-c", 'open("%s","w").write("1")' % filename]
+            pid = os.fork()
+            if pid == 0:
+                os.execv(progname, l)
+            else:
+                os.waitpid(pid, 0)
+        func = compile(does_stuff, [])
+        func()
+        assert open(filename).read() == "1"
+


More information about the pypy-svn mailing list