[pypy-svn] r15363 - in pypy/dist/pypy/translator/c: . src test

arigo at codespeak.net arigo at codespeak.net
Fri Jul 29 18:23:12 CEST 2005


Author: arigo
Date: Fri Jul 29 18:23:09 2005
New Revision: 15363

Modified:
   pypy/dist/pypy/translator/c/extfunc.py
   pypy/dist/pypy/translator/c/src/ll_time.h
   pypy/dist/pypy/translator/c/test/test_extfunc.py
   pypy/dist/pypy/translator/c/test/test_genc.py
Log:
* time.sleep() in genc.
* enable_fast_compilation() for faster testing in genc.
* support old versions of gcc in buildpyxmodule.
* a new test that checks that all suggested_primitive functions from
   the rtyper are really implemented in genc.  (os.ftruncate to be done
   in the next few minutes)


Modified: pypy/dist/pypy/translator/c/extfunc.py
==============================================================================
--- pypy/dist/pypy/translator/c/extfunc.py	(original)
+++ pypy/dist/pypy/translator/c/extfunc.py	Fri Jul 29 18:23:09 2005
@@ -19,7 +19,8 @@
     ll_os  .ll_os_lseek:   'LL_os_lseek',
     ll_os  .ll_os_isatty:  'LL_os_isatty',
     ll_time.ll_time_clock: 'LL_time_clock',
-    ll_time.ll_time_time: 'LL_time_time',
+    ll_time.ll_time_sleep: 'LL_time_sleep',
+    ll_time.ll_time_time:  'LL_time_time',
     ll_math.ll_math_frexp: 'LL_math_frexp',
     ll_math.ll_math_atan2: 'LL_math_atan2',
     ll_math.ll_math_fmod : 'LL_math_fmod',

Modified: pypy/dist/pypy/translator/c/src/ll_time.h
==============================================================================
--- pypy/dist/pypy/translator/c/src/ll_time.h	(original)
+++ pypy/dist/pypy/translator/c/src/ll_time.h	Fri Jul 29 18:23:09 2005
@@ -51,11 +51,54 @@
 #endif /* MS_WINDOWS */
 
 
-double LL_time_time(void) /* xxx had support for better resolutions */
+void LL_time_sleep(double secs)
 {
-	return ll_floattime();
+#if defined(MS_WINDOWS)
+	double millisecs = secs * 1000.0;
+	unsigned long ul_millis;
+
+	if (millisecs > (double)ULONG_MAX) {
+		RaiseSimpleException(Exc_OverflowError,
+				     "sleep length is too large");
+		return;
+	}
+	ul_millis = (unsigned long)millisecs;
+	if (ul_millis == 0)
+		Sleep(ul_millis);
+	else {
+		DWORD rc;
+		ResetEvent(hInterruptEvent);
+		rc = WaitForSingleObject(hInterruptEvent, ul_millis);
+		if (rc == WAIT_OBJECT_0) {
+				/* Yield to make sure real Python signal
+				 * handler called.
+				 */
+			Sleep(1);
+			RaiseSimpleException(Exc_IOError, "interrupted");
+			return;
+		}
+	}
+#else
+	struct timeval t;
+	double frac;
+	frac = fmod(secs, 1.0);
+	secs = floor(secs);
+	t.tv_sec = (long)secs;
+	t.tv_usec = (long)(frac*1000000.0);
+	if (select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &t) != 0) {
+#ifdef EINTR
+		if (errno != EINTR) {
+#else
+		if (1) {
+#endif
+			RaiseSimpleException(Exc_IOError, "select() failed");
+			return;
+		}
+	}
+#endif
 }
 
+
 static double
 ll_floattime(void)
 {
@@ -63,3 +106,8 @@
 	time(&secs);
 	return (double)secs;
 }
+
+double LL_time_time(void) /* xxx had support for better resolutions */
+{
+	return ll_floattime();
+}

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 Jul 29 18:23:09 2005
@@ -3,6 +3,17 @@
 import os, time
 from pypy.tool.udir import udir
 from pypy.translator.c.test.test_genc import compile
+from pypy.translator.c.extfunc import EXTERNALS
+
+def test_all_suggested_primitives():
+    for modulename in ['ll_math', 'll_os', 'll_os_path', 'll_time']:
+        mod = __import__('pypy.rpython.module.%s' % modulename,
+                         None, None, ['__doc__'])
+        for func in mod.__dict__.values():
+            if getattr(func, 'suggested_primitive', False):
+                yield suggested_primitive_implemented, func
+def suggested_primitive_implemented(func):
+    assert func in EXTERNALS, "missing C implementation for %r" % (func,)
 
 
 def test_time_clock():
@@ -15,6 +26,16 @@
     t2 = time.clock()
     assert t0 <= t1 <= t2
 
+def test_time_sleep():
+    def does_nothing():
+        time.sleep(0.19)
+    f1 = compile(does_nothing, [])
+    t0 = time.time()
+    f1()
+    t1 = time.time()
+    assert t0 <= t1
+    assert t1 - t0 >= 0.15
+
 
 def test_os_open():
     tmpfile = str(udir.join('test_os_open.txt'))

Modified: pypy/dist/pypy/translator/c/test/test_genc.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_genc.py	(original)
+++ pypy/dist/pypy/translator/c/test/test_genc.py	Fri Jul 29 18:23:09 2005
@@ -8,6 +8,7 @@
 from pypy.objspace.flow.model import Block, Link, FunctionGraph
 from pypy.tool.udir import udir
 from pypy.translator.tool.buildpyxmodule import make_module_from_c
+from pypy.translator.tool.buildpyxmodule import enable_fast_compilation
 from pypy.translator.gensupp import uniquemodulename
 
 # XXX this tries to make compiling faster for full-scale testing
@@ -17,6 +18,7 @@
 
 
 def compile_db(db):
+    enable_fast_compilation()  # for testing
     modulename = uniquemodulename('testing')
     targetdir = udir.join(modulename).ensure(dir=1)
     gen_source(db, modulename, str(targetdir), defines={'COUNT_OP_MALLOCS': 1})



More information about the Pypy-commit mailing list