Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r87487:2d371cd33c0f
Date: 2016-10-01 10:46 +0200
http://bitbucket.org/pypy/pypy/changeset/2d371cd33c0f/

Log:    Expose all defined 'CLOCK_' names from rtime.py

diff --git a/pypy/module/__pypy__/__init__.py b/pypy/module/__pypy__/__init__.py
--- a/pypy/module/__pypy__/__init__.py
+++ b/pypy/module/__pypy__/__init__.py
@@ -19,12 +19,8 @@
     if rtime.HAS_CLOCK_GETTIME:
         interpleveldefs["clock_gettime"] = "interp_time.clock_gettime"
         interpleveldefs["clock_getres"] = "interp_time.clock_getres"
-        for name in [
-            "CLOCK_REALTIME", "CLOCK_MONOTONIC", "CLOCK_MONOTONIC_RAW",
-            "CLOCK_PROCESS_CPUTIME_ID", "CLOCK_THREAD_CPUTIME_ID"
-        ]:
-            if getattr(rtime, name) is not None:
-                interpleveldefs[name] = "space.wrap(%d)" % getattr(rtime, name)
+        for name in rtime.ALL_DEFINED_CLOCKS:
+            interpleveldefs[name] = "space.wrap(%d)" % getattr(rtime, name)
 
 
 class ThreadModule(MixedModule):
diff --git a/rpython/rlib/rtime.py b/rpython/rlib/rtime.py
--- a/rpython/rlib/rtime.py
+++ b/rpython/rlib/rtime.py
@@ -200,6 +200,9 @@
     # clock_gettime().  The issue is that we'd need a way that keeps
     # nanosecond precision, depending on the usage, so we can't have a
     # nice function that returns the time as a float.
+    ALL_DEFINED_CLOCKS = [const for const in constant_names
+                          if const.startswith('CLOCK_')
+                             and globals()[const] is not None]
 
 if need_rusage:
     RUSAGE = RUSAGE
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to