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

tismer at codespeak.net tismer at codespeak.net
Tue Oct 31 14:47:11 CET 2006


Author: tismer
Date: Tue Oct 31 14:47:08 2006
New Revision: 33952

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:


Modified: pypy/dist/pypy/rpython/extfunctable.py
==============================================================================
--- pypy/dist/pypy/rpython/extfunctable.py	(original)
+++ pypy/dist/pypy/rpython/extfunctable.py	Tue Oct 31 14:47:08 2006
@@ -227,6 +227,8 @@
     declare(os.readlink , str,            'll_os/readlink')
 if hasattr(os, 'fork'):
     declare(os.fork ,     int,            'll_os/fork')
+if hasattr(os, 'spawnv'):
+    declare(os.spawnv,    int,            'll_os/spawnv')
 if hasattr(os, 'waitpid'):
     declare(os.waitpid ,  waitpidannotation, 'll_os/waitpid')
 

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	Tue Oct 31 14:47:08 2006
@@ -163,6 +163,10 @@
         return os.fork()
     ll_os_fork.suggested_primitive = True
 
+    def ll_os_spawnv(cls, mode, path, args):
+        return os.spawnv(mode, path, args)
+    ll_os_spawnv.suggested_primitive = True
+
     def ll_os_waitpid(cls, pid, options):
         pid, status = os.waitpid(pid, options)
         return cls.ll_waitpid_result(pid, status)

Modified: pypy/dist/pypy/translator/c/extfunc.py
==============================================================================
--- pypy/dist/pypy/translator/c/extfunc.py	(original)
+++ pypy/dist/pypy/translator/c/extfunc.py	Tue Oct 31 14:47:08 2006
@@ -56,6 +56,7 @@
     impl.ll_os_symlink.im_func: 'LL_os_symlink',
     impl.ll_readlink_into:      'LL_readlink_into',
     impl.ll_os_fork.im_func:    'LL_os_fork',
+    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',
     ll_time.ll_time_clock: 'LL_time_clock',
@@ -183,7 +184,7 @@
 
     for func, funcobj in db.externalfuncs.items():
         c_name = EXTERNALS[func]
-        # construct a define LL_NEED_<modname> to make it possible to isolate in-develpoment externals and headers
+        # construct a define LL_NEED_<modname> to make it possible to isolate in-development externals and headers
         modname = module_name(c_name)
         if modname not in modules:
             modules[modname] = True

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	Tue Oct 31 14:47:08 2006
@@ -77,6 +77,7 @@
 void LL_os_symlink(RPyString * path1, RPyString * path2);
 long LL_readlink_into(RPyString *path, RPyString *buffer);
 long LL_os_fork(void);
+long LL_os_spawnv(int mode, RPyString *path, RPyListOfString *args);
 RPyWAITPID_RESULT* LL_os_waitpid(long pid, long options);
 void LL_os__exit(long status);
 void LL_os_putenv(RPyString * name_eq_value);
@@ -375,7 +376,28 @@
 }
 #endif
 
+#ifdef HAVE_SPAWNV
+long LL_os_spawnv(int mode, RPyString *path, RPyListOfString *args) {
+	int pid, i, nargs = args->l_length;
+	char **slist = malloc((nargs+1) * sizeof(char*));
+	pid = -1;
+	if (slist) {
+		for (i=0; i<nargs; i++)
+			slist[i] = RPyString_AsString(args->l_items->items[i]);
+		slist[nargs] = NULL;
+		pid = spawnv(mode, RPyString_AsString(path), slist);
+		free(slist);
+	}
+	if (pid == -1)
+		RPYTHON_RAISE_OSERROR(errno);
+	return pid;
+}
+#endif
+
 #ifdef LL_NEED_OS_WAITPID
+/* note: LL_NEED_ is computed in extfunc.py, can't grep */
+
+#ifdef HAVE_WAITPID
 RPyWAITPID_RESULT* LL_os_waitpid(long pid, long options) {
 	int status;
 	pid = waitpid(pid, &status, options);
@@ -385,6 +407,21 @@
 	}
 	return ll_waitpid_result(pid, status);
 }
+
+#elif defined(HAVE_CWAIT)
+
+RPyWAITPID_RESULT* LL_os_waitpid(long pid, long options) {
+	int status;
+	pid = _cwait(&status, pid, options);
+	if (pid == -1) {
+		RPYTHON_RAISE_OSERROR(errno);
+		return NULL;
+	}
+		/* shift the status left a byte so this is more like the
+		   POSIX waitpid */
+	return ll_waitpid_result(pid, status << 8);
+}
+#endif /* HAVE_WAITPID || HAVE_CWAIT */
 #endif
 
 void LL_os__exit(long status) {

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	Tue Oct 31 14:47:08 2006
@@ -573,6 +573,27 @@
         status1 = f1()
         assert os.WIFEXITED(status1)
         assert os.WEXITSTATUS(status1) == 4
+elif hasattr(os, 'waitpid'):
+    # windows has no fork but some waitpid to be emulated
+    def test_waitpid():
+        def does_stuff():
+            prog = sys.executable
+            prog = str(prog)
+            args = [prog]
+            args += [] # uaah, become var-sized
+#            args = [prog, '-c', 'print 7*7']
+            args.append('-c')
+            args.append('"import os;os._exit(4)"')
+            pid = os.spawnv(os.P_NOWAIT, prog, args)
+            #if pid == 0:   # child
+            #    os._exit(4)
+            pid1, status1 = os.waitpid(pid, 0)
+            assert pid1 == pid
+            return status1
+        f1 = compile(does_stuff, [])
+        status1 = f1()
+        # for what reason do they want us to shift by 8? See the doc
+        assert status1 >> 8 == 4
 
 # ____________________________________________________________
 



More information about the Pypy-commit mailing list