Skip to content

Commit b257a00

Browse files
committed
Make sdists created on Linux compatible with other OSes
Cython doesn't compile 'IF SYSTEM_UNAME' checks into appropriate C checks like '#ifdef __linux__'. Instead it evaluates the constant at the build time, meaning that IF SYSTEM_UNAME == 'Linux': cdef extern from "sys/epoll.h": ... will be compiled to simple "include <sys/epoll.h>" (unguarded) on Linux, meaning that the result C file won't compile on other OSes. This commit moves the platform check to compat.h.
1 parent 76ed636 commit b257a00

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

uvloop/handles/poll.pyx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ cdef class UVPoll(UVHandle):
6161
self._fatal_error(exc, True)
6262
return
6363

64-
IF UNAME_SYSNAME == "Linux":
64+
cdef:
65+
int backend_id
66+
system.epoll_event dummy_event
67+
68+
if system.PLATFORM_IS_LINUX:
6569
# libuv doesn't remove the FD from epoll immediately
6670
# after uv_poll_stop or uv_poll_close, causing hard
6771
# to debug issue with dup-ed file descriptors causing
@@ -71,10 +75,6 @@ cdef class UVPoll(UVHandle):
7175
# It's safe though to manually call epoll_ctl here,
7276
# after calling uv_poll_stop.
7377

74-
cdef:
75-
int backend_id
76-
system.epoll_event dummy_event
77-
7878
backend_id = uv.uv_backend_fd(self._loop.uvloop)
7979
if backend_id != -1:
8080
memset(&dummy_event, 0, sizeof(dummy_event))

uvloop/includes/compat.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,14 @@
1616
#else
1717
#define PLATFORM_IS_APPLE 0
1818
#endif
19+
20+
21+
#ifdef __linux__
22+
# define PLATFORM_IS_LINUX 1
23+
# include <sys/epoll.h>
24+
#else
25+
# define PLATFORM_IS_LINUX 0
26+
# define EPOLL_CTL_DEL 2
27+
struct epoll_event {};
28+
int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event) {};
29+
#endif

uvloop/includes/system.pxd

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,13 @@ cdef extern from "pthread.h" nogil:
6262
cdef extern from "includes/compat.h" nogil:
6363

6464
cdef int EWOULDBLOCK
65-
cdef int PLATFORM_IS_APPLE
66-
6765

68-
IF UNAME_SYSNAME == "Linux":
69-
70-
cdef extern from "sys/epoll.h" nogil:
66+
cdef int PLATFORM_IS_APPLE
67+
cdef int PLATFORM_IS_LINUX
7168

72-
struct epoll_event:
73-
# We don't use the fields
74-
pass
69+
struct epoll_event:
70+
# We don't use the fields
71+
pass
7572

76-
int EPOLL_CTL_DEL
77-
int epoll_ctl(int epfd, int op, int fd, epoll_event *event)
73+
int EPOLL_CTL_DEL
74+
int epoll_ctl(int epfd, int op, int fd, epoll_event *event)

0 commit comments

Comments
 (0)