Commits

Armin Rigo  committed dab1ba5

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.

  • Participants
  • Parent commits 2c2944d

Comments (0)

Files changed (3)

File pypy/module/select/__init__.py

 # Package initialisation
 from pypy.interpreter.mixedmodule import MixedModule
 
-import select
 import sys
 
 
         '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

File pypy/module/select/interp_epoll.py

     ("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)
 

File pypy/module/select/test/test_epoll.py

 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([])