[pypy-commit] pypy default: Expose select.epoll() on Linux, even if we are building pypy or running

arigo noreply at buildbot.pypy.org
Tue Jan 31 15:33:51 CET 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r51988:dab1ba579e09
Date: 2012-01-31 15:33 +0100
http://bitbucket.org/pypy/pypy/changeset/dab1ba579e09/

Log:	Expose select.epoll() on Linux, even if we are building pypy or
	running tests with Python 2.5, where the 'select' module doesn't
	have epoll yet.

diff --git a/pypy/module/select/__init__.py b/pypy/module/select/__init__.py
--- a/pypy/module/select/__init__.py
+++ b/pypy/module/select/__init__.py
@@ -1,7 +1,6 @@
 # Package initialisation
 from pypy.interpreter.mixedmodule import MixedModule
 
-import select
 import sys
 
 
@@ -15,18 +14,13 @@
         'error' : 'space.fromcache(interp_select.Cache).w_error'
     }
 
-    # TODO: this doesn't feel right...
-    if hasattr(select, "epoll"):
+    if sys.platform.startswith('linux'):
         interpleveldefs['epoll'] = 'interp_epoll.W_Epoll'
-        symbols = [
-            "EPOLLIN", "EPOLLOUT", "EPOLLPRI", "EPOLLERR", "EPOLLHUP",
-            "EPOLLET", "EPOLLONESHOT", "EPOLLRDNORM", "EPOLLRDBAND",
-            "EPOLLWRNORM", "EPOLLWRBAND", "EPOLLMSG"
-        ]
-        for symbol in symbols:
-            if hasattr(select, symbol):
-                interpleveldefs[symbol] = "space.wrap(%s)" % getattr(select, symbol)
-
+        from pypy.module.select.interp_epoll import cconfig, public_symbols
+        for symbol in public_symbols:
+            value = cconfig[symbol]
+            if value is not None:
+                interpleveldefs[symbol] = "space.wrap(%r)" % value
 
     def buildloaders(cls):
         from pypy.rlib import rpoll
diff --git a/pypy/module/select/interp_epoll.py b/pypy/module/select/interp_epoll.py
--- a/pypy/module/select/interp_epoll.py
+++ b/pypy/module/select/interp_epoll.py
@@ -29,8 +29,16 @@
     ("data", CConfig.epoll_data)
 ])
 
+public_symbols = [
+    "EPOLLIN", "EPOLLOUT", "EPOLLPRI", "EPOLLERR", "EPOLLHUP",
+    "EPOLLET", "EPOLLONESHOT", "EPOLLRDNORM", "EPOLLRDBAND",
+    "EPOLLWRNORM", "EPOLLWRBAND", "EPOLLMSG"
+    ]
+for symbol in public_symbols:
+    setattr(CConfig, symbol, rffi_platform.DefinedConstantInteger(symbol))
+
 for symbol in ["EPOLL_CTL_ADD", "EPOLL_CTL_MOD", "EPOLL_CTL_DEL"]:
-    setattr(CConfig, symbol, rffi_platform.DefinedConstantInteger(symbol))
+    setattr(CConfig, symbol, rffi_platform.ConstantInteger(symbol))
 
 cconfig = rffi_platform.configure(CConfig)
 
diff --git a/pypy/module/select/test/test_epoll.py b/pypy/module/select/test/test_epoll.py
--- a/pypy/module/select/test/test_epoll.py
+++ b/pypy/module/select/test/test_epoll.py
@@ -1,23 +1,17 @@
 import py
+import sys
 
 from pypy.conftest import gettestobjspace
 
 
 class AppTestEpoll(object):
     def setup_class(cls):
+        # NB. we should ideally py.test.skip() if running on an old linux
+        # where the kernel doesn't support epoll()
+        if not sys.platform.startswith('linux'):
+            py.test.skip("test requires linux (assumed >= 2.6)")
         cls.space = gettestobjspace(usemodules=["select", "_socket", "posix"])
 
-        import errno
-        import select
-
-        if not hasattr(select, "epoll"):
-            py.test.skip("test requires linux 2.6")
-        try:
-            select.epoll()
-        except IOError, e:
-            if e.errno == errno.ENOSYS:
-                py.test.skip("kernel doesn't support epoll()")
-
     def setup_method(self, meth):
         self.w_sockets = self.space.wrap([])
 


More information about the pypy-commit mailing list