aresch / pyenet

A python wrapper for the ENet library
BSD 3-Clause "New" or "Revised" License
53 stars 30 forks source link

Linux and Windows build error - _ENetPeer struct #26

Closed Novark closed 3 years ago

Novark commented 3 years ago

I've tried building on both Windows 10 and a fresh Linux (Ubuntu 20.04.2.0 x64) install, and got the same error on both platforms.

Have I missed something here? Any help would be appreciated. Thanks in advance.

Linux build output follows:

python3 setup.py build
running build
running build_ext
cythoning enet.pyx to enet.c
/home/Novark/.local/lib/python3.8/site-packages/Cython/Compiler/Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /home/Novark/.local/lib/python3.8/site-packages/pyenet/enet.pyx
  tree = Parsing.p_module(s, pxd, full_module_name)
building 'enet' extension
creating build
creating build/temp.linux-x86_64-3.8
creating build/temp.linux-x86_64-3.8/enet
x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DHAS_POLL -DHAS_FCNTL -DHAS_MSGHDR_FLAGS -DHAS_SOCKLEN_T -DHAS_GETHOSTBYNAME_R -DHAS_GETHOSTBYADDR_R -Ienet/include/ -I/usr/include/python3.8 -c enet.c -o build/temp.linux-x86_64-3.8/enet.o -O3
enet.c: In function ‘__pyx_pf_4enet_4Peer_13needsDispatch___get__’:
enet.c:11053:62: error: ‘ENetPeer’ {aka ‘struct _ENetPeer’} has no member named ‘needsDispatch’
11053 |     __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_self->_enet_peer->needsDispatch); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 767, __pyx_L1_error)
      |                                                              ^~
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
Novark commented 3 years ago

I decided to dig into this a little bit, and discovered that the problem seems to be that this repo hasn't been kept up-to-date with the ENet library. There have been several changes in the past couple of years, one of which has been renaming the needsDispatch struct member to flags (presumably for future extensibility with ENetPeer's).

To fix this issue, I had to simply modify the enet.pyx file and change the following lines:

line 105:  int needsDispatch
...
line 764:  property needsDispatch:
line 765:      def __get__(self):
line 766:          if self.check_valid():
line 767:              return self._enet_peer.needsDispatch

to instead read:

line 105:  enet_uint16 flags
...
line 764:  property flags:
line 765:      def __get__(self):
line 766:          if self.check_valid():
line 767:              return self._enet_peer.flags

I've made a PR, but I'm leaving this note here for completeness and context.