Commit 5f3b60ab authored by Jason Madden's avatar Jason Madden

libev-cffi: Use nlink_t and let the compiler fill in the definition.

Fixes #1372.

This may require a slightly stricter adherance to POSIX? It is defined by IEEE Std 1003.1 2004 (http://pubs.opengroup.org/onlinepubs/009696699/basedefs/sys/types.h.html)
parent 1f8b3fa2
......@@ -44,6 +44,10 @@
- Avoid unbounded memory usage when creating very deep spawn trees.
Reported in :issue:`1371` by dmrlawson.
- libev-cffi: Let the compiler fill in the definition of ``nlink_t`` for
``st_nlink`` in ``struct stat``, instead of trying to guess it
ourself. Reported in :issue:`1372` by Andreas Schwab.
1.4.0 (2019-01-04)
==================
......
......@@ -15,18 +15,6 @@ import struct
__all__ = []
def system_bits():
return struct.calcsize('P') * 8
def st_nlink_type():
if sys.platform == "darwin" or sys.platform.startswith("freebsd"):
return "short"
if system_bits() == 32:
return "unsigned long"
return "long long"
from cffi import FFI
ffi = FFI()
......@@ -38,11 +26,15 @@ def read_source(name):
_cdef = read_source('_corecffi_cdef.c')
_source = read_source('_corecffi_source.c')
_cdef = _cdef.replace('#define GEVENT_ST_NLINK_T int', '')
# These defines and uses help keep the C file readable and lintable by
# C tools.
_cdef = _cdef.replace('#define GEVENT_STRUCT_DONE int', '')
_cdef = _cdef.replace('GEVENT_ST_NLINK_T', st_nlink_type())
_cdef = _cdef.replace("GEVENT_STRUCT_DONE _;", '...;')
_cdef = _cdef.replace('#define GEVENT_ST_NLINK_T int',
'typedef int... nlink_t;')
_cdef = _cdef.replace('GEVENT_ST_NLINK_T', 'nlink_t')
if sys.platform.startswith('win'):
# We must have the vfd_open, etc, functions on
......
......@@ -19,8 +19,8 @@ static void python_handle_error(void* handle, int revents);
static void python_stop(void* handle);
static void _gevent_generic_callback(struct ev_loop* loop,
struct ev_watcher* watcher,
int revents)
struct ev_watcher* watcher,
int revents)
{
void* handle = watcher->data;
int cb_result = python_callback(handle, revents);
......@@ -45,7 +45,7 @@ static void _gevent_generic_callback(struct ev_loop* loop,
default:
fprintf(stderr,
"WARNING: gevent: Unexpected return value %d from Python callback "
"for watcher %p and handle %d\n",
"for watcher %p and handle %p\n",
cb_result,
watcher, handle);
// XXX: Possible leaking of resources here? Should we be
......
# pylint: disable=no-member
# This module is only used to create and compile the gevent._corecffi module;
# This module is only used to create and compile the gevent.libuv._corecffi module;
# nothing should be directly imported from it except `ffi`, which should only be
# used for `ffi.compile()`; programs should import gevent._corecfffi.
# However, because we are using "out-of-line" mode, it is necessary to examine
......@@ -16,17 +16,6 @@ __all__ = []
WIN = sys.platform.startswith('win32')
def system_bits():
return struct.calcsize('P') * 8
def st_nlink_type():
if sys.platform == "darwin" or sys.platform.startswith("freebsd"):
return "short"
if system_bits() == 32:
return "unsigned long"
return "long long"
from cffi import FFI
ffi = FFI()
......@@ -39,12 +28,17 @@ def read_source(name):
_cdef = read_source('_corecffi_cdef.c')
_source = read_source('_corecffi_source.c')
_cdef = _cdef.replace('#define GEVENT_ST_NLINK_T int', '')
# These defines and uses help keep the C file readable and lintable by
# C tools.
_cdef = _cdef.replace('#define GEVENT_STRUCT_DONE int', '')
_cdef = _cdef.replace('#define GEVENT_UV_OS_SOCK_T int', '')
_cdef = _cdef.replace('GEVENT_ST_NLINK_T', st_nlink_type())
_cdef = _cdef.replace("GEVENT_STRUCT_DONE _;", '...;')
_cdef = _cdef.replace('#define GEVENT_ST_NLINK_T int',
'typedef int... nlink_t;')
_cdef = _cdef.replace('GEVENT_ST_NLINK_T', 'nlink_t')
_cdef = _cdef.replace('#define GEVENT_UV_OS_SOCK_T int', '')
# uv_os_sock_t is int on POSIX and SOCKET on Win32, but socket is
# just another name for handle, which is just another name for 'void*'
# which we will treat as an 'unsigned long' or 'unsigned long long'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment