Commit 210ed6c9 authored by Jason Madden's avatar Jason Madden

Run cythonize from setup.py

This eliminates our sdist-time dependency on Makefile or make.cmd on
Windows. Fewer moving pieces are better.

Fixes #1076
parent 63c9318f
...@@ -7,8 +7,14 @@ build/ ...@@ -7,8 +7,14 @@ build/
*.egg-info *.egg-info
gevent.*.[ch] gevent.*.[ch]
src/gevent/__pycache__ src/gevent/__pycache__
src/gevent/_semaphore.c
src/gevent/local.c
src/gevent/libev/corecext.c
src/gevent/libev/corecext.h
src/gevent/libev/_corecffi.c src/gevent/libev/_corecffi.c
src/gevent/libev/_corecffi.o src/gevent/libev/_corecffi.o
src/gevent/ares.c
src/gevent/ares.h
Makefile.ext Makefile.ext
MANIFEST MANIFEST
*_flymake.py *_flymake.py
......
...@@ -61,6 +61,22 @@ Platform Support ...@@ -61,6 +61,22 @@ Platform Support
still be installed on them. Supporting code will be removed in the still be installed on them. Supporting code will be removed in the
next version of gevent. See :issue:`1073`. next version of gevent. See :issue:`1073`.
Build Changes
-------------
- When building gevent from a source checkout (*not* a distributed
source distribution), ``make`` is no longer required and the
``Makefile`` is not used. Neither is an external ``cython`` command.
Instead, the ``cythonize`` function is used, as recommended by
Cython. See :issue:`1076`.
- :class:`gevent.local.local` is compiled with Cython on CPython. It
was already 5 to 6 times faster due to the work on :issue:`1020`,
and compiling it with Cython makes it another 5 to 6 times faster, for a
total speed up of about 35 times. It is now in the same ballpark as
the native :class:`threading.local` class. See :pr:`1024`.
Other Changes Other Changes
------------- -------------
...@@ -120,12 +136,6 @@ Other Changes ...@@ -120,12 +136,6 @@ Other Changes
implementing more of the attribute protocols directly. Please open implementing more of the attribute protocols directly. Please open
an issue if you have any compatibility problems. See :issue:`1020`. an issue if you have any compatibility problems. See :issue:`1020`.
- :class:`gevent.local.local` is compiled with Cython on CPython. It
was already 5 to 6 times faster due to the work on :issue:`1020`,
and compiling it with Cython makes it another 5 to 6 times faster, for a
total speed up of about 35 times. It is now in the same ballpark as
the native :class:`threading.local` class. See :pr:`1024`.
- More safely terminate subprocesses on Windows with - More safely terminate subprocesses on Windows with
:meth:`gevent.subprocess.Popen.terminate`. Reported in :issue:`1023` :meth:`gevent.subprocess.Popen.terminate`. Reported in :issue:`1023`
by Giacomo Debidda. by Giacomo Debidda.
......
...@@ -12,38 +12,11 @@ export PATH:=$(BUILD_RUNTIMES)/snakepit:$(TOOLS):$(PATH) ...@@ -12,38 +12,11 @@ export PATH:=$(BUILD_RUNTIMES)/snakepit:$(TOOLS):$(PATH)
export LC_ALL=C.UTF-8 export LC_ALL=C.UTF-8
all: src/gevent/libev/gevent.corecext.c src/gevent/gevent.ares.c src/gevent/gevent._semaphore.c src/gevent/gevent._local.c
src/gevent/libev/gevent.corecext.c: src/gevent/libev/corecext.pyx src/gevent/libev/libev.pxd src/gevent/libev/libev.h
$(CYTHON) -o gevent.corecext.c src/gevent/libev/corecext.pyx
echo '#include "callbacks.c"' >> gevent.corecext.c
mv gevent.corecext.* src/gevent/libev/
src/gevent/gevent.ares.c: src/gevent/ares.pyx src/gevent/*.pxd
$(CYTHON) -o gevent.ares.c src/gevent/ares.pyx
mv gevent.ares.* src/gevent/
src/gevent/gevent._semaphore.c: src/gevent/_semaphore.py src/gevent/_semaphore.pxd
# On PyPy, if we wanted to use Cython to compile _semaphore.py, we'd
# need to have _semaphore named as a .pyx file so it doesn't get
# loaded in preference to the .so. (We want to keep the definitions
# separate in a .pxd file for ease of reading, and that only works
# with .py files, so we'd have to copy them back and forth.)
# cp src/gevent/_semaphore.pyx src/gevent/_semaphore.py
$(CYTHON) -o gevent._semaphore.c src/gevent/_semaphore.py
mv gevent._semaphore.* src/gevent/
# rm src/gevent/_semaphore.py
src/gevent/gevent._local.c: src/gevent/local.py
$(CYTHON) -o gevent._local.c src/gevent/local.py
mv gevent._local.* src/gevent/
clean: clean:
rm -f gevent.corecext.c gevent.corecext.h src/gevent/libev/gevent.corecext.c src/gevent/libev/gevent.corecext.h rm -f src/gevent/libev/corecext.c src/gevent/libev/corecext.h
rm -f gevent.ares.c gevent.ares.h src/gevent/gevent.ares.c src/gevent/gevent.ares.h rm -f src/gevent/ares.c src/gevent/ares.h
rm -f gevent._semaphore.c gevent._semaphore.h src/gevent/gevent._semaphore.c src/gevent/gevent._semaphore.h rm -f src/gevent/_semaphore.c src/gevent/_semaphore.h
rm -f gevent._local.c gevent._local.h src/gevent/gevent._local.c src/gevent/gevent._local.h rm -f src/gevent/local.c src/gevent/local.h
rm -f src/gevent/*.so src/gevent/libev/*.so src/gevent/libuv/*.so rm -f src/gevent/*.so src/gevent/libev/*.so src/gevent/libuv/*.so
rm -rf src/gevent/libev/*.o src/gevent/libuv/*.o src/gevent/*.o rm -rf src/gevent/libev/*.o src/gevent/libuv/*.o src/gevent/*.o
rm -rf src/gevent/__pycache__ src/greentest/__pycache__ src/gevent/libev/__pycache__ rm -rf src/gevent/__pycache__ src/greentest/__pycache__ src/gevent/libev/__pycache__
......
...@@ -24,6 +24,7 @@ from _setuputils import DEFINE_MACROS ...@@ -24,6 +24,7 @@ from _setuputils import DEFINE_MACROS
from _setuputils import glob_many from _setuputils import glob_many
from _setuputils import dep_abspath from _setuputils import dep_abspath
from _setuputils import RUNNING_ON_CI from _setuputils import RUNNING_ON_CI
from _setuputils import cythonize1
CARES_EMBED = should_embed('c-ares') CARES_EMBED = should_embed('c-ares')
...@@ -79,8 +80,8 @@ def configure_ares(bext, ext): ...@@ -79,8 +80,8 @@ def configure_ares(bext, ext):
ARES = Extension(name='gevent.ares', ARES = Extension(name='gevent.ares',
sources=['src/gevent/gevent.ares.c'], sources=['src/gevent/ares.pyx'],
include_dirs=[dep_abspath('c-ares')] if CARES_EMBED else [], include_dirs=['src/gevent'] + [dep_abspath('c-ares')] if CARES_EMBED else [],
libraries=list(LIBRARIES), libraries=list(LIBRARIES),
define_macros=list(DEFINE_MACROS), define_macros=list(DEFINE_MACROS),
depends=glob_many('src/gevent/dnshelper.c', depends=glob_many('src/gevent/dnshelper.c',
...@@ -107,3 +108,5 @@ if CARES_EMBED: ...@@ -107,3 +108,5 @@ if CARES_EMBED:
else: else:
ARES.libraries.append('cares') ARES.libraries.append('cares')
ARES.define_macros += [('HAVE_NETDB_H', '')] ARES.define_macros += [('HAVE_NETDB_H', '')]
ARES = cythonize1(ARES)
...@@ -19,6 +19,7 @@ from _setuputils import DEFINE_MACROS ...@@ -19,6 +19,7 @@ from _setuputils import DEFINE_MACROS
from _setuputils import glob_many from _setuputils import glob_many
from _setuputils import dep_abspath from _setuputils import dep_abspath
from _setuputils import should_embed from _setuputils import should_embed
from _setuputils import cythonize1
LIBEV_EMBED = should_embed('libev') LIBEV_EMBED = should_embed('libev')
...@@ -60,8 +61,8 @@ def configure_libev(bext, ext): ...@@ -60,8 +61,8 @@ def configure_libev(bext, ext):
os.chdir(cwd) os.chdir(cwd)
CORE = Extension(name='gevent.libev.corecext', CORE = Extension(name='gevent.libev.corecext',
sources=['src/gevent/libev/gevent.corecext.c'], sources=['src/gevent/libev/corecext.pyx'],
include_dirs=[dep_abspath('libev')] if LIBEV_EMBED else [], include_dirs=['src/gevent/libev'] + [dep_abspath('libev')] if LIBEV_EMBED else [],
libraries=list(LIBRARIES), libraries=list(LIBRARIES),
define_macros=list(DEFINE_MACROS), define_macros=list(DEFINE_MACROS),
depends=glob_many('src/gevent/libev/callbacks.*', depends=glob_many('src/gevent/libev/callbacks.*',
...@@ -86,3 +87,15 @@ if LIBEV_EMBED: ...@@ -86,3 +87,15 @@ if LIBEV_EMBED:
CORE.define_macros.append(('EV_VERIFY', os.environ['GEVENTSETUP_EV_VERIFY'])) CORE.define_macros.append(('EV_VERIFY', os.environ['GEVENTSETUP_EV_VERIFY']))
else: else:
CORE.libraries.append('ev') CORE.libraries.append('ev')
CORE = cythonize1(CORE)
# XXX The include of callbacks.c must go at the end of the
# file because it references things cython generates.
# How can we do this automatically, or relax that restriction?
with open(CORE.sources[0]) as f:
core_data = f.read()
if '#include "callbacks.c"' not in core_data:
with open(CORE.sources[0], 'a') as f:
f.write('\n#include "callbacks.c"\n')
...@@ -12,8 +12,9 @@ import sys ...@@ -12,8 +12,9 @@ import sys
from subprocess import check_call from subprocess import check_call
from glob import glob from glob import glob
from setuptools import Extension as _Extension
from setuptools.command.build_ext import build_ext from setuptools.command.build_ext import build_ext
from setuptools.command.sdist import sdist
## Exported configurations ## Exported configurations
...@@ -143,6 +144,35 @@ def system(cmd, cwd=None, env=None, **kwargs): ...@@ -143,6 +144,35 @@ def system(cmd, cwd=None, env=None, **kwargs):
sys.exit(1) sys.exit(1)
# Cython
try:
from Cython.Build import cythonize
except ImportError:
# The .c files had better already exist. Based on code from
# http://cython.readthedocs.io/en/latest/src/reference/compilation.html#distributing-cython-modules
def cythonize(extensions):
for extension in extensions:
sources = []
for sfile in extension.sources:
path, ext = os.path.splitext(sfile)
if ext in ('.pyx', '.py'):
ext = '.c'
sfile = path + ext
sources.append(sfile)
extension.sources[:] = sources
return extensions
def cythonize1(ext):
new_ext = cythonize([ext], include_path=['src/gevent', 'src/gevent/libev'])[0]
for optional_attr in ('configure', 'optional'):
if hasattr(ext, optional_attr):
setattr(new_ext, optional_attr,
getattr(ext, optional_attr))
return new_ext
## Distutils extensions ## Distutils extensions
class BuildFailed(Exception): class BuildFailed(Exception):
pass pass
...@@ -170,55 +200,7 @@ class ConfiguringBuildExt(build_ext): ...@@ -170,55 +200,7 @@ class ConfiguringBuildExt(build_ext):
return result return result
class MakeSdist(sdist):
"""
An sdist that runs make if needed, and makes sure
that the Makefile doesn't make it into the dist
archive.
"""
_ran_make = False
@classmethod
def make(cls, targets=''):
# NOTE: We have two copies of the makefile, one
# for posix, one for windows. Our sdist command takes
# care of renaming the posix one so it doesn't get into
# the .tar.gz file (we don't want to re-run make in a released
# file). We trigger off the presence/absence of that file altogether
# to skip both posix and unix branches.
# See https://github.com/gevent/gevent/issues/757
if cls._ran_make:
return
if os.path.exists('Makefile'):
if WIN:
# make.cmd handles checking for PyPy and only making the
# right things, so we can ignore the targets
system("appveyor\\make.cmd")
else:
if "PYTHON" not in os.environ:
os.environ["PYTHON"] = sys.executable
# Let the user specify the make program, helpful for BSD
# where GNU make might be called gmake
make_program = os.environ.get('MAKE', 'make')
system(make_program + ' ' + targets)
cls._ran_make = True
def run(self):
renamed = False
if os.path.exists('Makefile'):
self.make()
os.rename('Makefile', 'Makefile.ext')
renamed = True
try:
return sdist.run(self)
finally:
if renamed:
os.rename('Makefile.ext', 'Makefile')
from setuptools import Extension as _Extension
class Extension(_Extension): class Extension(_Extension):
# This class exists currently mostly to make pylint # This class exists currently mostly to make pylint
......
...@@ -165,8 +165,7 @@ test_script: ...@@ -165,8 +165,7 @@ test_script:
after_test: after_test:
# We already built the wheel during build_script, because it's # We already built the wheel during build_script, because it's
# much faster to do that and install from the wheel than to # much faster to do that and install from the wheel than to
# rebuild it here (because we wind up re-building all the cython # rebuild it here
# code, even though it's already built on disk; our make.cmd is not smart)
#- "%CMD_IN_ENV% %PYEXE% setup.py bdist_wheel bdist_wininst" #- "%CMD_IN_ENV% %PYEXE% setup.py bdist_wheel bdist_wininst"
- ps: "ls dist" - ps: "ls dist"
......
IF "%PYTHON_EXE%" == "python" (
cython -o gevent.corecext.c src\gevent\libev\corecext.pyx
type src\gevent\libev\callbacks.c >> gevent.corecext.c
move gevent.corecext.* src\gevent\libev
)
cython -o gevent.ares.c src\gevent\ares.pyx
move gevent.ares.* src\gevent
cython -o gevent._semaphore.c src\gevent\_semaphore.py
move gevent._semaphore.* src\gevent
cython -o gevent._local.c src\gevent\local.py
move gevent._local.c src\gevent
When updating c-ares, remember to copy ares.h to cares.h.
The original ares.h conflicts with the ares.h generated automatically
by cython for src/gevent/ares.pyx.
/* Copyright 1998 by the Massachusetts Institute of Technology.
* Copyright (C) 2007-2013 by Daniel Stenberg
*
* Permission to use, copy, modify, and distribute this
* software and its documentation for any purpose and without
* fee is hereby granted, provided that the above copyright
* notice appear in all copies and that both that copyright
* notice and this permission notice appear in supporting
* documentation, and that the name of M.I.T. not be used in
* advertising or publicity pertaining to distribution of the
* software without specific, written prior permission.
* M.I.T. makes no representations about the suitability of
* this software for any purpose. It is provided "as is"
* without express or implied warranty.
*/
#ifndef ARES__H
#define ARES__H
#include "ares_version.h" /* c-ares version defines */
#include "ares_build.h" /* c-ares build definitions */
#include "ares_rules.h" /* c-ares rules enforcement */
/*
* Define WIN32 when build target is Win32 API
*/
#if (defined(_WIN32) || defined(__WIN32__)) && \
!defined(WIN32) && !defined(__SYMBIAN32__)
# define WIN32
#endif
#include <sys/types.h>
/* HP-UX systems version 9, 10 and 11 lack sys/select.h and so does oldish
libc5-based Linux systems. Only include it on system that are known to
require it! */
#if defined(_AIX) || defined(__NOVELL_LIBC__) || defined(__NetBSD__) || \
defined(__minix) || defined(__SYMBIAN32__) || defined(__INTEGRITY) || \
defined(ANDROID) || defined(__ANDROID__) || defined(__OpenBSD__) || \
defined(__QNXNTO__)
#include <sys/select.h>
#endif
#if (defined(NETWARE) && !defined(__NOVELL_LIBC__))
#include <sys/bsdskt.h>
#endif
#if defined(WATT32)
# include <netinet/in.h>
# include <sys/socket.h>
# include <tcp.h>
#elif defined(_WIN32_WCE)
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# endif
# include <windows.h>
# include <winsock.h>
#elif defined(WIN32)
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# endif
# include <windows.h>
# include <winsock2.h>
# include <ws2tcpip.h>
#else
# include <sys/socket.h>
# include <netinet/in.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
/*
** c-ares external API function linkage decorations.
*/
#ifdef CARES_STATICLIB
# define CARES_EXTERN
#elif defined(WIN32) || defined(_WIN32) || defined(__SYMBIAN32__)
# if defined(CARES_BUILDING_LIBRARY)
# define CARES_EXTERN __declspec(dllexport)
# else
# define CARES_EXTERN __declspec(dllimport)
# endif
#elif defined(CARES_BUILDING_LIBRARY) && defined(CARES_SYMBOL_HIDING)
# define CARES_EXTERN CARES_SYMBOL_SCOPE_EXTERN
#else
# define CARES_EXTERN
#endif
#define ARES_SUCCESS 0
/* Server error codes (ARES_ENODATA indicates no relevant answer) */
#define ARES_ENODATA 1
#define ARES_EFORMERR 2
#define ARES_ESERVFAIL 3
#define ARES_ENOTFOUND 4
#define ARES_ENOTIMP 5
#define ARES_EREFUSED 6
/* Locally generated error codes */
#define ARES_EBADQUERY 7
#define ARES_EBADNAME 8
#define ARES_EBADFAMILY 9
#define ARES_EBADRESP 10
#define ARES_ECONNREFUSED 11
#define ARES_ETIMEOUT 12
#define ARES_EOF 13
#define ARES_EFILE 14
#define ARES_ENOMEM 15
#define ARES_EDESTRUCTION 16
#define ARES_EBADSTR 17
/* ares_getnameinfo error codes */
#define ARES_EBADFLAGS 18
/* ares_getaddrinfo error codes */
#define ARES_ENONAME 19
#define ARES_EBADHINTS 20
/* Uninitialized library error code */
#define ARES_ENOTINITIALIZED 21 /* introduced in 1.7.0 */
/* ares_library_init error codes */
#define ARES_ELOADIPHLPAPI 22 /* introduced in 1.7.0 */
#define ARES_EADDRGETNETWORKPARAMS 23 /* introduced in 1.7.0 */
/* More error codes */
#define ARES_ECANCELLED 24 /* introduced in 1.7.0 */
/* Flag values */
#define ARES_FLAG_USEVC (1 << 0)
#define ARES_FLAG_PRIMARY (1 << 1)
#define ARES_FLAG_IGNTC (1 << 2)
#define ARES_FLAG_NORECURSE (1 << 3)
#define ARES_FLAG_STAYOPEN (1 << 4)
#define ARES_FLAG_NOSEARCH (1 << 5)
#define ARES_FLAG_NOALIASES (1 << 6)
#define ARES_FLAG_NOCHECKRESP (1 << 7)
#define ARES_FLAG_EDNS (1 << 8)
/* Option mask values */
#define ARES_OPT_FLAGS (1 << 0)
#define ARES_OPT_TIMEOUT (1 << 1)
#define ARES_OPT_TRIES (1 << 2)
#define ARES_OPT_NDOTS (1 << 3)
#define ARES_OPT_UDP_PORT (1 << 4)
#define ARES_OPT_TCP_PORT (1 << 5)
#define ARES_OPT_SERVERS (1 << 6)
#define ARES_OPT_DOMAINS (1 << 7)
#define ARES_OPT_LOOKUPS (1 << 8)
#define ARES_OPT_SOCK_STATE_CB (1 << 9)
#define ARES_OPT_SORTLIST (1 << 10)
#define ARES_OPT_SOCK_SNDBUF (1 << 11)
#define ARES_OPT_SOCK_RCVBUF (1 << 12)
#define ARES_OPT_TIMEOUTMS (1 << 13)
#define ARES_OPT_ROTATE (1 << 14)
#define ARES_OPT_EDNSPSZ (1 << 15)
#define ARES_OPT_NOROTATE (1 << 16)
/* Nameinfo flag values */
#define ARES_NI_NOFQDN (1 << 0)
#define ARES_NI_NUMERICHOST (1 << 1)
#define ARES_NI_NAMEREQD (1 << 2)
#define ARES_NI_NUMERICSERV (1 << 3)
#define ARES_NI_DGRAM (1 << 4)
#define ARES_NI_TCP 0
#define ARES_NI_UDP ARES_NI_DGRAM
#define ARES_NI_SCTP (1 << 5)
#define ARES_NI_DCCP (1 << 6)
#define ARES_NI_NUMERICSCOPE (1 << 7)
#define ARES_NI_LOOKUPHOST (1 << 8)
#define ARES_NI_LOOKUPSERVICE (1 << 9)
/* Reserved for future use */
#define ARES_NI_IDN (1 << 10)
#define ARES_NI_IDN_ALLOW_UNASSIGNED (1 << 11)
#define ARES_NI_IDN_USE_STD3_ASCII_RULES (1 << 12)
/* Addrinfo flag values */
#define ARES_AI_CANONNAME (1 << 0)
#define ARES_AI_NUMERICHOST (1 << 1)
#define ARES_AI_PASSIVE (1 << 2)
#define ARES_AI_NUMERICSERV (1 << 3)
#define ARES_AI_V4MAPPED (1 << 4)
#define ARES_AI_ALL (1 << 5)
#define ARES_AI_ADDRCONFIG (1 << 6)
/* Reserved for future use */
#define ARES_AI_IDN (1 << 10)
#define ARES_AI_IDN_ALLOW_UNASSIGNED (1 << 11)
#define ARES_AI_IDN_USE_STD3_ASCII_RULES (1 << 12)
#define ARES_AI_CANONIDN (1 << 13)
#define ARES_AI_MASK (ARES_AI_CANONNAME|ARES_AI_NUMERICHOST|ARES_AI_PASSIVE| \
ARES_AI_NUMERICSERV|ARES_AI_V4MAPPED|ARES_AI_ALL| \
ARES_AI_ADDRCONFIG)
#define ARES_GETSOCK_MAXNUM 16 /* ares_getsock() can return info about this
many sockets */
#define ARES_GETSOCK_READABLE(bits,num) (bits & (1<< (num)))
#define ARES_GETSOCK_WRITABLE(bits,num) (bits & (1 << ((num) + \
ARES_GETSOCK_MAXNUM)))
/* c-ares library initialization flag values */
#define ARES_LIB_INIT_NONE (0)
#define ARES_LIB_INIT_WIN32 (1 << 0)
#define ARES_LIB_INIT_ALL (ARES_LIB_INIT_WIN32)
/*
* Typedef our socket type
*/
#ifndef ares_socket_typedef
#ifdef WIN32
typedef SOCKET ares_socket_t;
#define ARES_SOCKET_BAD INVALID_SOCKET
#else
typedef int ares_socket_t;
#define ARES_SOCKET_BAD -1
#endif
#define ares_socket_typedef
#endif /* ares_socket_typedef */
typedef void (*ares_sock_state_cb)(void *data,
ares_socket_t socket_fd,
int readable,
int writable);
struct apattern;
/* NOTE about the ares_options struct to users and developers.
This struct will remain looking like this. It will not be extended nor
shrunk in future releases, but all new options will be set by ares_set_*()
options instead of with the ares_init_options() function.
Eventually (in a galaxy far far away), all options will be settable by
ares_set_*() options and the ares_init_options() function will become
deprecated.
When new options are added to c-ares, they are not added to this
struct. And they are not "saved" with the ares_save_options() function but
instead we encourage the use of the ares_dup() function. Needless to say,
if you add config options to c-ares you need to make sure ares_dup()
duplicates this new option.
*/
struct ares_options {
int flags;
int timeout; /* in seconds or milliseconds, depending on options */
int tries;
int ndots;
unsigned short udp_port;
unsigned short tcp_port;
int socket_send_buffer_size;
int socket_receive_buffer_size;
struct in_addr *servers;
int nservers;
char **domains;
int ndomains;
char *lookups;
ares_sock_state_cb sock_state_cb;
void *sock_state_cb_data;
struct apattern *sortlist;
int nsort;
int ednspsz;
};
struct hostent;
struct timeval;
struct sockaddr;
struct ares_channeldata;
typedef struct ares_channeldata *ares_channel;
typedef void (*ares_callback)(void *arg,
int status,
int timeouts,
unsigned char *abuf,
int alen);
typedef void (*ares_host_callback)(void *arg,
int status,
int timeouts,
struct hostent *hostent);
typedef void (*ares_nameinfo_callback)(void *arg,
int status,
int timeouts,
char *node,
char *service);
typedef int (*ares_sock_create_callback)(ares_socket_t socket_fd,
int type,
void *data);
typedef int (*ares_sock_config_callback)(ares_socket_t socket_fd,
int type,
void *data);
CARES_EXTERN int ares_library_init(int flags);
CARES_EXTERN int ares_library_init_mem(int flags,
void *(*amalloc)(size_t size),
void (*afree)(void *ptr),
void *(*arealloc)(void *ptr, size_t size));
CARES_EXTERN int ares_library_initialized(void);
CARES_EXTERN void ares_library_cleanup(void);
CARES_EXTERN const char *ares_version(int *version);
CARES_EXTERN int ares_init(ares_channel *channelptr);
CARES_EXTERN int ares_init_options(ares_channel *channelptr,
struct ares_options *options,
int optmask);
CARES_EXTERN int ares_save_options(ares_channel channel,
struct ares_options *options,
int *optmask);
CARES_EXTERN void ares_destroy_options(struct ares_options *options);
CARES_EXTERN int ares_dup(ares_channel *dest,
ares_channel src);
CARES_EXTERN void ares_destroy(ares_channel channel);
CARES_EXTERN void ares_cancel(ares_channel channel);
/* These next 3 configure local binding for the out-going socket
* connection. Use these to specify source IP and/or network device
* on multi-homed systems.
*/
CARES_EXTERN void ares_set_local_ip4(ares_channel channel, unsigned int local_ip);
/* local_ip6 should be 16 bytes in length */
CARES_EXTERN void ares_set_local_ip6(ares_channel channel,
const unsigned char* local_ip6);
/* local_dev_name should be null terminated. */
CARES_EXTERN void ares_set_local_dev(ares_channel channel,
const char* local_dev_name);
CARES_EXTERN void ares_set_socket_callback(ares_channel channel,
ares_sock_create_callback callback,
void *user_data);
CARES_EXTERN void ares_set_socket_configure_callback(ares_channel channel,
ares_sock_config_callback callback,
void *user_data);
CARES_EXTERN int ares_set_sortlist(ares_channel channel,
const char *sortstr);
/*
* Virtual function set to have user-managed socket IO.
* Note that all functions need to be defined, and when
* set, the library will not do any bind nor set any
* socket options, assuming the client handles these
* through either socket creation or the
* ares_sock_config_callback call.
*/
struct iovec;
struct ares_socket_functions {
ares_socket_t(*asocket)(int, int, int, void *);
int(*aclose)(ares_socket_t, void *);
int(*aconnect)(ares_socket_t, const struct sockaddr *, ares_socklen_t, void *);
ares_ssize_t(*arecvfrom)(ares_socket_t, void *, size_t, int, struct sockaddr *, ares_socklen_t *, void *);
ares_ssize_t(*asendv)(ares_socket_t, const struct iovec *, int, void *);
};
CARES_EXTERN void ares_set_socket_functions(ares_channel channel,
const struct ares_socket_functions * funcs,
void *user_data);
CARES_EXTERN void ares_send(ares_channel channel,
const unsigned char *qbuf,
int qlen,
ares_callback callback,
void *arg);
CARES_EXTERN void ares_query(ares_channel channel,
const char *name,
int dnsclass,
int type,
ares_callback callback,
void *arg);
CARES_EXTERN void ares_search(ares_channel channel,
const char *name,
int dnsclass,
int type,
ares_callback callback,
void *arg);
CARES_EXTERN void ares_gethostbyname(ares_channel channel,
const char *name,
int family,
ares_host_callback callback,
void *arg);
CARES_EXTERN int ares_gethostbyname_file(ares_channel channel,
const char *name,
int family,
struct hostent **host);
CARES_EXTERN void ares_gethostbyaddr(ares_channel channel,
const void *addr,
int addrlen,
int family,
ares_host_callback callback,
void *arg);
CARES_EXTERN void ares_getnameinfo(ares_channel channel,
const struct sockaddr *sa,
ares_socklen_t salen,
int flags,
ares_nameinfo_callback callback,
void *arg);
CARES_EXTERN int ares_fds(ares_channel channel,
fd_set *read_fds,
fd_set *write_fds);
CARES_EXTERN int ares_getsock(ares_channel channel,
ares_socket_t *socks,
int numsocks);
CARES_EXTERN struct timeval *ares_timeout(ares_channel channel,
struct timeval *maxtv,
struct timeval *tv);
CARES_EXTERN void ares_process(ares_channel channel,
fd_set *read_fds,
fd_set *write_fds);
CARES_EXTERN void ares_process_fd(ares_channel channel,
ares_socket_t read_fd,
ares_socket_t write_fd);
CARES_EXTERN int ares_create_query(const char *name,
int dnsclass,
int type,
unsigned short id,
int rd,
unsigned char **buf,
int *buflen,
int max_udp_size);
CARES_EXTERN int ares_mkquery(const char *name,
int dnsclass,
int type,
unsigned short id,
int rd,
unsigned char **buf,
int *buflen);
CARES_EXTERN int ares_expand_name(const unsigned char *encoded,
const unsigned char *abuf,
int alen,
char **s,
long *enclen);
CARES_EXTERN int ares_expand_string(const unsigned char *encoded,
const unsigned char *abuf,
int alen,
unsigned char **s,
long *enclen);
/*
* NOTE: before c-ares 1.7.0 we would most often use the system in6_addr
* struct below when ares itself was built, but many apps would use this
* private version since the header checked a HAVE_* define for it. Starting
* with 1.7.0 we always declare and use our own to stop relying on the
* system's one.
*/
struct ares_in6_addr {
union {
unsigned char _S6_u8[16];
} _S6_un;
};
struct ares_addrttl {
struct in_addr ipaddr;
int ttl;
};
struct ares_addr6ttl {
struct ares_in6_addr ip6addr;
int ttl;
};
struct ares_srv_reply {
struct ares_srv_reply *next;
char *host;
unsigned short priority;
unsigned short weight;
unsigned short port;
};
struct ares_mx_reply {
struct ares_mx_reply *next;
char *host;
unsigned short priority;
};
struct ares_txt_reply {
struct ares_txt_reply *next;
unsigned char *txt;
size_t length; /* length excludes null termination */
};
/* NOTE: This structure is a superset of ares_txt_reply
*/
struct ares_txt_ext {
struct ares_txt_ext *next;
unsigned char *txt;
size_t length;
/* 1 - if start of new record
* 0 - if a chunk in the same record */
unsigned char record_start;
};
struct ares_naptr_reply {
struct ares_naptr_reply *next;
unsigned char *flags;
unsigned char *service;
unsigned char *regexp;
char *replacement;
unsigned short order;
unsigned short preference;
};
struct ares_soa_reply {
char *nsname;
char *hostmaster;
unsigned int serial;
unsigned int refresh;
unsigned int retry;
unsigned int expire;
unsigned int minttl;
};
/*
** Parse the buffer, starting at *abuf and of length alen bytes, previously
** obtained from an ares_search call. Put the results in *host, if nonnull.
** Also, if addrttls is nonnull, put up to *naddrttls IPv4 addresses along with
** their TTLs in that array, and set *naddrttls to the number of addresses
** so written.
*/
CARES_EXTERN int ares_parse_a_reply(const unsigned char *abuf,
int alen,
struct hostent **host,
struct ares_addrttl *addrttls,
int *naddrttls);
CARES_EXTERN int ares_parse_aaaa_reply(const unsigned char *abuf,
int alen,
struct hostent **host,
struct ares_addr6ttl *addrttls,
int *naddrttls);
CARES_EXTERN int ares_parse_ptr_reply(const unsigned char *abuf,
int alen,
const void *addr,
int addrlen,
int family,
struct hostent **host);
CARES_EXTERN int ares_parse_ns_reply(const unsigned char *abuf,
int alen,
struct hostent **host);
CARES_EXTERN int ares_parse_srv_reply(const unsigned char* abuf,
int alen,
struct ares_srv_reply** srv_out);
CARES_EXTERN int ares_parse_mx_reply(const unsigned char* abuf,
int alen,
struct ares_mx_reply** mx_out);
CARES_EXTERN int ares_parse_txt_reply(const unsigned char* abuf,
int alen,
struct ares_txt_reply** txt_out);
CARES_EXTERN int ares_parse_txt_reply_ext(const unsigned char* abuf,
int alen,
struct ares_txt_ext** txt_out);
CARES_EXTERN int ares_parse_naptr_reply(const unsigned char* abuf,
int alen,
struct ares_naptr_reply** naptr_out);
CARES_EXTERN int ares_parse_soa_reply(const unsigned char* abuf,
int alen,
struct ares_soa_reply** soa_out);
CARES_EXTERN void ares_free_string(void *str);
CARES_EXTERN void ares_free_hostent(struct hostent *host);
CARES_EXTERN void ares_free_data(void *dataptr);
CARES_EXTERN const char *ares_strerror(int code);
struct ares_addr_node {
struct ares_addr_node *next;
int family;
union {
struct in_addr addr4;
struct ares_in6_addr addr6;
} addr;
};
struct ares_addr_port_node {
struct ares_addr_port_node *next;
int family;
union {
struct in_addr addr4;
struct ares_in6_addr addr6;
} addr;
int udp_port;
int tcp_port;
};
CARES_EXTERN int ares_set_servers(ares_channel channel,
struct ares_addr_node *servers);
CARES_EXTERN int ares_set_servers_ports(ares_channel channel,
struct ares_addr_port_node *servers);
/* Incomming string format: host[:port][,host[:port]]... */
CARES_EXTERN int ares_set_servers_csv(ares_channel channel,
const char* servers);
CARES_EXTERN int ares_set_servers_ports_csv(ares_channel channel,
const char* servers);
CARES_EXTERN int ares_get_servers(ares_channel channel,
struct ares_addr_node **servers);
CARES_EXTERN int ares_get_servers_ports(ares_channel channel,
struct ares_addr_port_node **servers);
CARES_EXTERN const char *ares_inet_ntop(int af, const void *src, char *dst,
ares_socklen_t size);
CARES_EXTERN int ares_inet_pton(int af, const char *src, void *dst);
#ifdef __cplusplus
}
#endif
#endif /* ARES__H */
...@@ -3,6 +3,14 @@ ...@@ -3,6 +3,14 @@
from __future__ import print_function from __future__ import print_function
import sys import sys
import os import os
import os.path
# setuptools is *required* on Windows
# (https://bugs.python.org/issue23246) and for PyPy. No reason not to
# use it everywhere. v24.2.0 is needed for python_requires
from setuptools import Extension, setup
from setuptools import find_packages
from _setuputils import read from _setuputils import read
from _setuputils import read_version from _setuputils import read_version
...@@ -10,14 +18,10 @@ from _setuputils import system ...@@ -10,14 +18,10 @@ from _setuputils import system
from _setuputils import PYPY, WIN from _setuputils import PYPY, WIN
from _setuputils import IGNORE_CFFI from _setuputils import IGNORE_CFFI
from _setuputils import ConfiguringBuildExt from _setuputils import ConfiguringBuildExt
from _setuputils import MakeSdist
from _setuputils import BuildFailed from _setuputils import BuildFailed
from _setuputils import cythonize1
# setuptools is *required* on Windows
# (https://bugs.python.org/issue23246) and for PyPy. No reason not to
# use it everywhere. v24.2.0 is needed for python_requires
from setuptools import Extension, setup
from setuptools import find_packages
if WIN: if WIN:
# Make sure the env vars that make.cmd needs are set # Make sure the env vars that make.cmd needs are set
...@@ -45,11 +49,12 @@ from _setupares import ARES ...@@ -45,11 +49,12 @@ from _setupares import ARES
SEMAPHORE = Extension(name="gevent._semaphore", SEMAPHORE = Extension(name="gevent._semaphore",
sources=["src/gevent/gevent._semaphore.c"]) sources=["src/gevent/_semaphore.py"])
SEMAPHORE = cythonize1(SEMAPHORE)
LOCAL = Extension(name="gevent.local", LOCAL = Extension(name="gevent.local",
sources=["src/gevent/gevent._local.c"]) sources=["src/gevent/local.py"])
LOCAL = cythonize1(LOCAL)
EXT_MODULES = [ EXT_MODULES = [
CORE, CORE,
...@@ -140,8 +145,6 @@ def run_setup(ext_modules, run_make): ...@@ -140,8 +145,6 @@ def run_setup(ext_modules, run_make):
if LIBEV_CFFI_MODULE in cffi_modules and not WIN: if LIBEV_CFFI_MODULE in cffi_modules and not WIN:
system(libev_configure_command) system(libev_configure_command)
MakeSdist.make()
setup( setup(
name='gevent', name='gevent',
version=__version__, version=__version__,
...@@ -158,7 +161,7 @@ def run_setup(ext_modules, run_make): ...@@ -158,7 +161,7 @@ def run_setup(ext_modules, run_make):
packages=find_packages('src'), packages=find_packages('src'),
include_package_data=True, include_package_data=True,
ext_modules=ext_modules, ext_modules=ext_modules,
cmdclass=dict(build_ext=ConfiguringBuildExt, sdist=MakeSdist), cmdclass=dict(build_ext=ConfiguringBuildExt),
install_requires=install_requires, install_requires=install_requires,
setup_requires=setup_requires, setup_requires=setup_requires,
# It's always safe to pass the CFFI keyword, even if # It's always safe to pass the CFFI keyword, even if
......
cdef extern from "ares.h": cdef extern from "cares.h":
struct ares_options: struct ares_options:
int flags int flags
void* sock_state_cb void* sock_state_cb
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include <netdb.h> #include <netdb.h>
#endif #endif
#include "ares.h" #include "cares.h"
#include "cares_ntop.h" #include "cares_ntop.h"
#include "cares_pton.h" #include "cares_pton.h"
......
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