Commit 35286088 authored by Jason Madden's avatar Jason Madden Committed by GitHub

Merge pull request #1376 from gevent/issue1372

libev-cffi: Use nlink_t and let the compiler fill in the definition.
parents 1f8b3fa2 18d198a4
......@@ -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)
==================
......
......@@ -187,6 +187,7 @@ if not WIN:
# Python API functions, and you're not supposed to do that from
# CFFI code. Plus I could never get the libraries= line to ffi.compile()
# correct to make linking work.
# Also, we use the type `nlink_t`, which is not defined on Windows.
cffi_modules.append(
LIBEV_CFFI_MODULE
)
......
......@@ -10,21 +10,9 @@ from __future__ import absolute_import, print_function
import sys
import os
import os.path # pylint:disable=no-name-in-module
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"
__all__ = []
from cffi import 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
......
......@@ -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
......@@ -10,23 +10,12 @@ from __future__ import absolute_import, print_function
import sys
import os
import os.path # pylint:disable=no-name-in-module
import struct
__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,18 @@ 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 _;", '...;')
# nlink_t is not used in libuv.
_cdef = _cdef.replace('#define GEVENT_ST_NLINK_T int',
'')
_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'
......
......@@ -353,7 +353,10 @@ def print_list(lst):
log(' - %s', name)
def _setup_environ(debug=False):
if 'PYTHONWARNINGS' not in os.environ and not sys.warnoptions:
if ('PYTHONWARNINGS' not in os.environ
and (not sys.warnoptions
# Python 3.7 goes from [] to ['default'] for nothing
or sys.warnoptions == ['default'])):
# action:message:category:module:line
os.environ['PYTHONWARNINGS'] = ','.join([
......@@ -373,6 +376,10 @@ def _setup_environ(debug=False):
'ignore:::importlib._bootstrap_external:',
# importing ABCs from collections, not collections.abc
'ignore:::pkg_resources._vendor.pyparsing:',
'ignore:::dns.namedict:',
# dns.hash itself is being deprecated, importing it raises the warning;
# we don't import it, but dnspython still does
'ignore:::dns.hash:',
])
if 'PYTHONFAULTHANDLER' not in os.environ:
......
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