pypy/module/test_lib_pypy/test_code_module.py::AppTestCodeModule::()::test_cause_tb
self = <CallInfo when='setup' exception: CompilationError(out="""
""")>
func = <function <lambda> at 0x0000010aa789cd40>, when = 'setup'
def __init__(self, func, when):
#: context of invocation: one of "setup", "call",
#: "teardown", "memocollect"
self.when = when
self.start = time()
try:
> self.result = func()
..\_pytest\runner.py:150:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> return CallInfo(lambda: ihook(item=item, **kwds), when=when)
..\_pytest\runner.py:138:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_HookCaller 'pytest_runtest_setup'>
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_cause_tb'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_cause_tb'>}
def __call__(self, **kwargs):
assert not self.is_historic()
> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
..\_pytest\vendored_packages\pluggy.py:724:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.config.PytestPluginManager object at 0x0000010aa35a1440>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000010aa4ec7aa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000010aa3a74660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000010aa3a746a0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_cause_tb'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_cause_tb'>}
def _hookexec(self, hook, methods, kwargs):
# called from all hookcaller instances.
# enable_tracing will set its own wrapping function at self._inner_hookexec
> return self._inner_hookexec(hook, methods, kwargs)
..\_pytest\vendored_packages\pluggy.py:338:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000010aa4ec7aa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000010aa3a74660>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000010aa3a746a0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_cause_tb'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_cause_tb'>}
self._inner_hookexec = lambda hook, methods, kwargs: \
> _MultiCall(methods, kwargs, hook.spec_opts).execute()
..\_pytest\vendored_packages\pluggy.py:333:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_cause_tb'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
> return _wrapped_call(hook_impl.function(*args), self.execute)
..\_pytest\vendored_packages\pluggy.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
wrap_controller = <generator object pytest_runtest_setup at 0x0000010aa78a2cf0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_cause_tb'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def _wrapped_call(wrap_controller, func):
""" Wrap calling to a function with a generator which needs to yield
exactly once. The yield point will trigger calling the wrapped function
and return its _CallOutcome to the yield point. The generator then needs
to finish (raise StopIteration) in order for the wrapped call to complete.
"""
try:
next(wrap_controller) # first yield
except StopIteration:
_raise_wrapfail(wrap_controller, "did not yield")
call_outcome = _CallOutcome(func)
try:
wrap_controller.send(call_outcome)
_raise_wrapfail(wrap_controller, "has second yield")
except StopIteration:
pass
> return call_outcome.get_result()
..\_pytest\vendored_packages\pluggy.py:253:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000010aa789bf20>
def get_result(self):
if self.excinfo is None:
return self.result
else:
ex = self.excinfo
if _py3:
raise ex[1].with_traceback(ex[2])
> _reraise(*ex) # noqa
..\_pytest\vendored_packages\pluggy.py:279:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_pytest.vendored_packages.pluggy._CallOutcome instance at 0x0000010aa789bf20>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_cause_tb'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>>
def __init__(self, func):
try:
> self.result = func()
..\_pytest\vendored_packages\pluggy.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_cause_tb'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>
def execute(self):
all_kwargs = self.kwargs
self.results = results = []
firstresult = self.specopts.get("firstresult")
while self.hook_impls:
hook_impl = self.hook_impls.pop()
args = [all_kwargs[argname] for argname in hook_impl.argnames]
if hook_impl.hookwrapper:
return _wrapped_call(hook_impl.function(*args), self.execute)
> res = hook_impl.function(*args)
..\_pytest\vendored_packages\pluggy.py:596:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
item = <AppTestMethod 'test_cause_tb'>
@pytest.hookimpl(tryfirst=True)
def pytest_runtest_setup(item):
if isinstance(item, pytest.Function):
config = item.config
if get_marker(item, name='pypy_only'):
if config.applevel is not None and not config.applevel.is_pypy:
pytest.skip('PyPy-specific test')
appclass = item.getparent(pytest.Class)
if appclass is not None:
from pypy.tool.pytest.objspace import gettestobjspace
# Make cls.space and cls.runappdirect available in tests.
spaceconfig = getattr(appclass.obj, 'spaceconfig', {})
> appclass.obj.space = gettestobjspace(**spaceconfig)
conftest.py:254:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
kwds = {'usemodules': ['struct']}
config = <rpython.config.config.Config object at 0x0000010aa78dafa8>
key = (((False, True, False, False, True, False, ...), True, None, False, None, False, ...), False, (False, 'lltype', 'c', False, True, 'ref', ...))
def gettestobjspace(**kwds):
""" helper for instantiating and caching spaces for testing.
"""
try:
config = make_config(option, **kwds)
except ConflictConfigError as e:
# this exception is typically only raised if a module is not available.
# in this case the test should be skipped
py.test.skip(str(e))
if getattr(option, 'runappdirect', None):
return TinyObjSpace()
key = config.getkey()
try:
return _SPACECACHE[key]
except KeyError:
> space = maketestobjspace(config)
tool\pytest\objspace.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000010aa78dafa8>
def maketestobjspace(config=None):
if config is None:
config = make_config(option)
if config.objspace.usemodules.thread:
config.translation.thread = True
config.objspace.extmodules = 'pypy.tool.pytest.fake_pytest'
> space = make_objspace(config)
tool\pytest\objspace.py:34:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
config = <rpython.config.config.Config object at 0x0000010aa78dafa8>
def make_objspace(config):
from pypy.objspace.std.objspace import StdObjSpace
> return StdObjSpace(config)
tool\option.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
config = <rpython.config.config.Config object at 0x0000010aa78dafa8>
@not_rpython
def __init__(self, config=None):
"Basic initialization of objects."
self.w_default_importlib_import = None
self.fromcache = InternalSpaceCache(self).getorbuild
self.threadlocals = ThreadLocals()
# set recursion limit
# sets all the internal descriptors
if config is None:
from pypy.config.pypyoption import get_pypy_config
config = get_pypy_config(translating=False)
self.config = config
self.reverse_debugging = config.translation.reverse_debugger
self.builtin_modules = {}
self.reloading_modules = {}
self.interned_strings = make_weak_value_dictionary(self, str, W_Root)
self.actionflag = ActionFlag() # changed by the signal module
self.check_signal_action = None # changed by the signal module
make_finalizer_queue(W_Root, self)
self._code_of_sys_exc_info = None
self._builtin_functions_by_identifier = {'': None}
# can be overridden to a subclass
> self.initialize()
interpreter\baseobjspace.py:458:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def initialize(self):
"""only for initializing the space
Setup all the object types and implementations.
"""
setup_prebuilt(self)
self.FrameClass = frame.build_frame(self)
self.StringObjectCls = W_BytesObject
self.UnicodeObjectCls = W_UnicodeObject
self.IntObjectCls = W_IntObject
self.FloatObjectCls = W_FloatObject
# singletons
self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
self.w_True = W_BoolObject.w_True
self.w_NotImplemented = self.wrap(special.NotImplemented())
self.w_Ellipsis = self.wrap(special.Ellipsis())
self.w_DisallowNew = self.wrap(special.DisallowNew())
# types
builtin_type_classes = {
W_BoolObject.typedef: W_BoolObject,
W_BytearrayObject.typedef: W_BytearrayObject,
W_BytesObject.typedef: W_BytesObject,
W_ComplexObject.typedef: W_ComplexObject,
W_DictMultiObject.typedef: W_DictMultiObject,
W_FloatObject.typedef: W_FloatObject,
W_IntObject.typedef: W_AbstractIntObject,
W_AbstractSeqIterObject.typedef: W_AbstractSeqIterObject,
W_ListObject.typedef: W_ListObject,
W_MemoryView.typedef: W_MemoryView,
W_NoneObject.typedef: W_NoneObject,
W_ObjectObject.typedef: W_ObjectObject,
W_SetObject.typedef: W_SetObject,
W_FrozensetObject.typedef: W_FrozensetObject,
W_SliceObject.typedef: W_SliceObject,
W_TupleObject.typedef: W_TupleObject,
W_TypeObject.typedef: W_TypeObject,
W_UnicodeObject.typedef: W_UnicodeObject,
}
self.builtin_types = {}
self._interplevel_classes = {}
for typedef, cls in builtin_type_classes.items():
w_type = self.gettypeobject(typedef)
self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
self._interplevel_classes[w_type] = cls
# The loop above sets space.w_str and space.w_bytes.
# We rename 'space.w_str' to 'space.w_unicode' and
# 'space.w_text'.
self.w_unicode = self.w_str
self.w_text = self.w_str
del self.w_str
self.w_long = self.w_int
self.w_dict.flag_map_or_seq = 'M'
from pypy.objspace.std import dictproxyobject
dictproxyobject._set_flag_map_or_seq(self)
self.w_list.flag_map_or_seq = 'S'
self.w_tuple.flag_map_or_seq = 'S'
self.builtin_types['str'] = self.w_unicode
self.builtin_types['bytes'] = self.w_bytes
self.builtin_types["NotImplemented"] = self.w_NotImplemented
self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
> self.make_builtins()
objspace\std\objspace.py:115:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = StdObjSpace
@not_rpython
def make_builtins(self):
"only for initializing the space."
from pypy.module.exceptions.moduledef import Module
w_name = self.newtext('__exceptions__')
self.exceptions_module = Module(self, w_name)
self.exceptions_module.install()
from pypy.module.imp.moduledef import Module
w_name = self.newtext('_imp')
> mod = Module(self, w_name)
interpreter\baseobjspace.py:637:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0x0000010aa786d018>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0x0000010aa79672e0>
def __init__(self, space, *args):
"NOT_RPYTHON"
MixedModule.__init__(self, space, *args)
from pypy.module.posix.interp_posix import add_fork_hook
> from pypy.module.imp import interp_imp
module\imp\moduledef.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> from pypy.module.imp import importing
module\imp\interp_imp.py:1:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
Implementation of the interpreter-level default import logic.
"""
import sys, os, stat, re, platform
from pypy.interpreter.module import Module, init_extra_module_attrs
from pypy.interpreter.gateway import interp2app, unwrap_spec
from pypy.interpreter.typedef import TypeDef, generic_new_descr
from pypy.interpreter.error import OperationError, oefmt, wrap_oserror
from pypy.interpreter.baseobjspace import W_Root, CannotHaveLock
from pypy.interpreter.eval import Code
from pypy.interpreter.pycode import PyCode
> from rpython.rlib import streamio, jit
module\imp\importing.py:14:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""New standard I/O library.
Based on sio.py from Guido van Rossum.
- This module contains various stream classes which provide a subset of the
classic Python I/O API: read(n), write(s), tell(), seek(offset, whence=0),
readall(), readline(), truncate(size), flush(), close(), peek(),
flushable(), try_to_find_file_descriptor().
- This is not for general usage:
* read(n) may return less than n bytes, just like os.read().
* some other methods also have no default parameters.
* close() should be called exactly once and no further operations performed;
there is no __del__() closing the stream for you.
* some methods may raise MyNotImplementedError.
* peek() returns some (or no) characters that have already been read ahead.
* flushable() returns True/False if flushing that stream is useful/pointless.
- A 'basis stream' provides I/O using a low-level API, like the os, mmap or
socket modules.
- A 'filtering stream' builds on top of another stream. There are filtering
streams for universal newline translation, for unicode translation, and
for buffering.
You typically take a basis stream, place zero or more filtering
streams on top of it, and then top it off with an input-buffering and/or
an outout-buffering stream.
"""
# File offsets are all 'r_longlong', but a single read or write cannot
# transfer more data that fits in an RPython 'int' (because that would not
# fit in a single string anyway). This module needs to be careful about
# where r_longlong values end up: as argument to seek() and truncate() and
# return value of tell(), but not as argument to read().
import os, sys, errno
from rpython.rlib.objectmodel import specialize, we_are_translated, not_rpython
from rpython.rlib.rarithmetic import r_longlong, intmask
> from rpython.rlib import rposix, nonconst, _rsocket_rffi as _c
..\rpython\rlib\streamio.py:40:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
from rpython.rtyper.lltypesystem import rffi
from rpython.rtyper.lltypesystem import lltype
from rpython.rtyper.tool import rffi_platform as platform
from rpython.rtyper.lltypesystem.rffi import CCHARP, CONST_CCHARP
from rpython.rlib import jit
from rpython.translator.tool.cbuild import ExternalCompilationInfo
from rpython.translator.platform import platform as target_platform
from rpython.rlib.rarithmetic import intmask, r_uint, widen
import os,sys
from textwrap import dedent
_POSIX = os.name == "posix"
_WIN32 = sys.platform == "win32"
_MSVC = target_platform.name == "msvc"
_MINGW = target_platform.name == "mingw32"
_SOLARIS = sys.platform == "sunos5"
_MACOSX = sys.platform == "darwin"
_HAS_AF_PACKET = sys.platform.startswith('linux') # only Linux for now
if _POSIX:
includes = ('sys/types.h',
'sys/socket.h',
'sys/un.h',
'poll.h',
'sys/select.h',
'sys/types.h',
'netinet/in.h',
'netinet/tcp.h',
'unistd.h',
'fcntl.h',
'stdio.h',
'netdb.h',
'arpa/inet.h',
'stdint.h',
'errno.h',
'limits.h',
'net/if.h',
)
if _HAS_AF_PACKET:
includes += ('netpacket/packet.h',
'sys/ioctl.h',
)
cond_includes = [('AF_NETLINK', 'linux/netlink.h')]
cond_includes += [('AF_ALG', 'linux/if_alg.h')]
cond_includes += [('AF_QIPCRTR', 'linux/qrtr.h')]
libraries = ()
calling_conv = 'c'
HEADER = ''.join(['#include <%s>\n' % filename for filename in includes])
COND_HEADER = ''.join(['#ifdef %s\n#include <%s>\n#endif\n' % cond_include
for cond_include in cond_includes])
if _SOLARIS:
libraries = libraries + ('socket', 'nsl')
if _WIN32:
includes = ()
libraries = ('ws2_32', 'Iphlpapi')
calling_conv = 'win'
header_lines = [
'#include <WinSock2.h>',
'#include <WS2tcpip.h>',
# winsock2 defines AF_UNIX, but not sockaddr_un
'#undef AF_UNIX',
]
if _MSVC:
header_lines.extend([
'#include <Mstcpip.h>',
# these types do not exist on microsoft compilers
'#ifdef _WIN64',
'typedef long long ssize_t;',
'typedef unsigned long long size_t;',
'#else',
'typedef int ssize_t;',
'typedef unsigned int size_t;',
'#endif',
'typedef unsigned __int16 uint16_t;',
'typedef unsigned __int32 uint32_t;',
])
else: # MINGW
includes = ('stdint.h',)
header_lines.extend([
'''\
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0501
#endif''',
'#define SIO_RCVALL _WSAIOW(IOC_VENDOR,1)',
'#define SIO_KEEPALIVE_VALS _WSAIOW(IOC_VENDOR,4)',
'#define RCVALL_OFF 0',
'#define RCVALL_ON 1',
'#define RCVALL_SOCKETLEVELONLY 2',
'''\
#ifndef __MINGW32__
struct tcp_keepalive {
u_long onoff;
u_long keepalivetime;
u_long keepaliveinterval;
};
#endif
'''
])
HEADER = '\n'.join(header_lines)
COND_HEADER = ''
constants = {}
eci = ExternalCompilationInfo(
post_include_bits = [HEADER, COND_HEADER],
includes = includes,
libraries = libraries,
)
class CConfig:
_compilation_info_ = eci
# constants
linux = platform.Defined('linux')
WIN32 = platform.Defined('_WIN32')
O_RDONLY = platform.DefinedConstantInteger('O_RDONLY')
O_WRONLY = platform.DefinedConstantInteger('O_WRONLY')
O_RDWR = platform.DefinedConstantInteger('O_RDWR')
O_NONBLOCK = platform.DefinedConstantInteger('O_NONBLOCK')
F_GETFL = platform.DefinedConstantInteger('F_GETFL')
F_SETFL = platform.DefinedConstantInteger('F_SETFL')
FIONBIO = platform.DefinedConstantInteger('FIONBIO')
PIPE_BUF = platform.DefinedConstantInteger('PIPE_BUF')
INVALID_SOCKET = platform.DefinedConstantInteger('INVALID_SOCKET')
INET_ADDRSTRLEN = platform.DefinedConstantInteger('INET_ADDRSTRLEN')
INET6_ADDRSTRLEN= platform.DefinedConstantInteger('INET6_ADDRSTRLEN')
EINTR = platform.DefinedConstantInteger('EINTR')
WSAEINTR = platform.DefinedConstantInteger('WSAEINTR')
EINPROGRESS = platform.DefinedConstantInteger('EINPROGRESS')
WSAEINPROGRESS = platform.DefinedConstantInteger('WSAEINPROGRESS')
EWOULDBLOCK = platform.DefinedConstantInteger('EWOULDBLOCK')
WSAEWOULDBLOCK = platform.DefinedConstantInteger('WSAEWOULDBLOCK')
EAFNOSUPPORT = platform.DefinedConstantInteger('EAFNOSUPPORT')
WSAEAFNOSUPPORT = platform.DefinedConstantInteger('WSAEAFNOSUPPORT')
EISCONN = platform.DefinedConstantInteger('EISCONN')
WSAEISCONN = platform.DefinedConstantInteger('WSAEISCONN')
constant_names = '''
AF_AAL5 AF_ALG AF_APPLETALK AF_ASH AF_ATMPVC AF_ATMSVC AF_AX25 AF_BLUETOOTH
AF_BRIDGE AF_CAN AD_DECnet AF_DEC AF_DECnet AF_DIVERT AF_ECONET AF_HYPERV
AF_INET AF_INET6 AF_IPX AF_IRDA AF_KEY AF_LINK AF_LLC AF_NETBEUI AF_NETLINK
AF_NETROM AF_PACKET AF_PPPOX AF_QIPCRTR AF_RDS AF_ROSE AF_ROUTE AF_SECURITY
AF_SNA AF_SYSTEM AF_TIPC AF_UNIX AF_VSOCK AF_WANPIPE AF_X25 AF_UNSPEC
AI_ADDRCONFIG AI_ALL AI_CANONNAME AI_DEFAULT AI_MASK AI_NUMERICHOST
AI_NUMERICSERV AI_PASSIVE AI_V4MAPPED AI_V4MAPPED_CFG
BTPROTO_HCI BTPROTO_L2CAP BTPROTO_SCO BTPROTO_RFCOMM
ALG_OP_DECRYPT ALG_OP_ENCRYPT ALG_OP_SIGN ALG_OP_VERIFY ALG_SET_AEAD_ASSOCLEN
ALG_SET_AEAD_AUTHSIZE ALG_SET_IV ALG_SET_KEY ALG_SET_OP ALG_SET_PUBKEY SOL_ALG
HCI_DATA_DIR HCI_FILTER HCI_TIME_STAMP
HV_PROTOCOL_RAW
HVSOCKET_ADDRESS_FLAG_PASSTHRU HVSOCKET_CONNECTED_SUSPEND
HVSOCKET_CONNECT_TIMEOUT HVSOCKET_CONNECT_TIMEOUT_MAX
INADDR_ALLHOSTS_GROUP INADDR_ANY INADDR_BROADCAST INADDR_LOOPBACK
INADDR_MAX_LOCAL_GROUP INADDR_NONE INADDR_UNSPEC_GROUP
IOCTL_VM_SOCKETS_GET_LOCAL_CID
EAI_ADDRFAMILY EAI_AGAIN EAI_BADFLAGS EAI_BADHINTS EAI_FAIL EAI_FAMILY EAI_MAX
EAI_MEMORY EAI_NODATA EAI_NONAME EAI_OVERFLOW EAI_PROTOCOL EAI_SERVICE
EAI_SOCKTYPE EAI_SYSTEM
IPPROTO_AH IPPROTO_BIP IPPROTO_CBT IPPROTO_DSTOPTS IPPROTO_EGP IPPROTO_EON IPPROTO_ESP
IPPROTO_FRAGMENT IPPROTO_GGP IPPROTO_GRE IPPROTO_HELLO IPPROTO_HOPOPTS IPPROTO_ICLFXBM
IPPROTO_ICMPV6 IPPROTO_IDP IPPROTO_IGP IPPROTO_IGMP IPPROTO_IPCOMP IPPROTO_IPIP
IPPROTO_IPV4 IPPROTO_IPV6 IPPROTO_L2TP IPPROTO_MAX IPPROTO_MOBILE IPPROTO_ND IPPROTO_NONE
IPPROTO_PGM IPPROTO_PIM IPPROTO_PUP IPPROTO_RDP IPPROTO_ROUTING IPPROTO_RSVP
IPPROTO_MPTCP IPPROTO_ST IPPROTO_TCP IPPROTO_TP IPPROTO_UDPLITE IPPROTO_VRRP IPPROTO_XTP IPPROTO_SCTP
IPV6_CHECKSUM IPV6_DONTFRAG IPV6_DSTOPTS IPV6_HOPLIMIT IPV6_HOPOPTS
IPV6_JOIN_GROUP IPV6_LEAVE_GROUP IPV6_MULTICAST_HOPS IPV6_MULTICAST_IF
IPV6_MULTICAST_LOOP IPV6_NEXTHOP IPV6_PATHMTU IPV6_PKTINFO IPV6_RECVDSTOPTS
IPV6_RECVHOPLIMIT IPV6_RECVHOPOPTS IPV6_RECVPATHMTU IPV6_RECVPKTINFO
IPV6_RECVRTHDR IPV6_RECVTCLASS IPV6_RTHDR IPV6_RTHDRDSTOPTS IPV6_RTHDR_TYPE_0
IPV6_TCLASS IPV6_UNICAST_HOPS IPV6_USE_MIN_MTU IPV6_V6ONLY
IP_ADD_MEMBERSHIP IP_ADD_SOURCE_MEMBERSHIP IP_BIND_ADDRESS_NO_PORT IP_BLOCK_SOURCE
IP_DEFAULT_MULTICAST_LOOP IP_DEFAULT_MULTICAST_TTL
IP_DROP_MEMBERSHIP IP_DROP_SOURCE_MEMBERSHIP IP_HDRINCL IP_MAX_MEMBERSHIPS
IP_MULTICAST_IF IP_MULTICAST_LOOP IP_MULTICAST_TTL IP_OPTIONS IP_PKTINFO
IP_RECVDSTADDR IP_RECVOPTS IP_RECVRETOPTS IP_RECVTOS IP_RETOPTS
IP_TOS IP_TRANSPARENT IP_TTL IP_UNBLOCK_SOURCE
MSG_BCAST MSG_BTAG MSG_CMSG_CLOEXEC MSG_CONFIRM MSG_CTRUNC MSG_DONTROUTE
MSG_DONTWAIT MSG_EOF MSG_ERRQUEUE MSG_EOR MSG_ETAG MSG_FASTOPEN MSG_MCAST
MSG_MORE MSG_NOSIGNAL MSG_NOTIFICATION MSG_OOB MSG_PEEK MSG_TRUNC MSG_WAITALL
NI_DGRAM NI_IDN NI_MAXHOST NI_MAXSERV NI_NAMEREQD NI_NOFQDN NI_NUMERICHOST
NI_NUMERICSERV
NETLINK_ARPD NETLINK_CRYPTO NETLINK_DNRTMSG NETLINK_FIREWALL NETLINK_IP6_FW
NETLINK_NFLOG NETLINK_ROUTE NETLINK_ROUTE6 NETLINK_SKIP NETLINK_TAPBASE
NETLINK_TCPDIAG NETLINK_USERSOCK NETLINK_W1 NETLINK_XFRM
PACKET_HOST PACKET_BROADCAST PACKET_MULTICAST PACKET_OTHERHOST PACKET_OUTGOING
PACKET_LOOPBACK PACKET_FASTROUTE
PF_CAN PF_DIVERT PF_PACKET PF_RDS PF_SYSTEM
RCVALL_IPLEVEL RCVALL_MAX RCVALL_OFF RCVALL_ON RCVALL_SOCKETLEVELONLY
RDS_CANCEL_SENT_TO RDS_CMSG_RDMA_ARGS RDS_CMSG_RDMA_DEST RDS_CMSG_RDMA_MAP
RDS_CMSG_RDMA_STATUS RDS_CMSG_RDMA_UPDATE RDS_CONG_MONITOR RDS_FREE_MR
RDS_GET_MR RDS_GET_MR_FOR_DEST RDS_RDMA_DONTWAIT RDS_RDMA_FENCE
RDS_RDMA_INVALIDATE RDS_RDMA_NOTIFY_ME RDS_RDMA_READWRITE RDS_RDMA_SILENT
RDS_RDMA_USE_ONCE RDS_RECVERR
SOCK_DGRAM SOCK_RAW SOCK_RDM SOCK_SEQPACKET SOCK_STREAM
SOCK_CLOEXEC SOCK_NONBLOCK
SOL_SOCKET SOL_IPX SOL_AX25 SOL_ATALK SOL_NETROM SOL_ROSE
SO_ACCEPTCONN SO_BINDTODEVICE SO_BINDTOIFINDEX SO_BROADCAST SO_DEBUG
SO_DOMAIN SO_DONTROUTE SO_ERROR SO_EXCLUSIVEADDRUSE SO_INCOMING_CPU
SO_J1939_ERRQUEUE SO_J1939_FILTER SO_J1939_PROMISC SO_J1939_SEND_PRIO
SO_KEEPALIVE SO_LINGER SO_MARK SO_OOBINLINE SO_PASSCRED SO_PASSSEC
SO_PEERCRED SO_PEERSEC SO_PRIORITY SO_PROTOCOL
SO_RCVBUF SO_RCVLOWAT SO_RCVTIMEO SO_REUSEADDR SO_REUSEPORT SO_RTABLE
SO_SETFIB SO_SNDBUF SO_SNDLOWAT SO_SNDTIMEO SO_TYPE SO_USELOOPBACK
SO_USER_COOKIE SO_VM_SOCKETS_BUFFER_MAX_SIZE SO_VM_SOCKETS_BUFFER_MIN_SIZE
SO_VM_SOCKETS_BUFFER_SIZE
SIO_KEEPALIVE_VALS SIO_LOOPBACK_FAST_PATH SIO_RCVALL
SYSPROTO_CONTROL
TCP_CC_INFO TCP_CONGESTION TCP_CONNECTION_INFO TCP_CORK TCP_DEFER_ACCEPT
TCP_FASTOPEN TCP_FASTOPEN_CONNECT TCP_FASTOPEN_KEY TCP_FASTOPEN_NO_COOKIE
TCP_INFO TCP_INQ TCP_KEEPALIVE TCP_KEEPCNT TCP_KEEPIDLE TCP_KEEPINTVL
TCP_LINGER2 TCP_MAXSEG TCP_MD5SIG TCP_MD5SIG_EXT TCP_NODELAY
TCP_NOTSENT_LOWAT TCP_QUEUE_SEQ TCP_QUICKACK TCP_REPAIR TCP_REPAIR_OPTIONS
TCP_REPAIR_QUEUE TCP_REPAIR_WINDOW TCP_SAVED_SYN TCP_SAVE_SYN TCP_SYNCNT
TCP_THIN_DUPACK TCP_THIN_LINEAR_TIMEOUTS TCP_TIMESTAMP TCP_TX_DELAY TCP_ULP
TCP_USER_TIMEOUT TCP_WINDOW_CLAMP TCP_ZEROCOPY_RECEIVE
IPX_TYPE
LOCAL_CREDS LOCAL_CREDS_PERSISTENT LOCAL_PEERCRED
SCM_CREDENTIALS SCM_CREDS SCM_CREDS2 SCM_J1939_DEST_ADDR SCM_J1939_DEST_NAME
SCM_J1939_ERRQUEUE SCM_J1939_PRIO SCM_RIGHTS
CAN_BCM CAN_BCM_CAN_FD_FRAME CAN_BCM_RX_ANNOUNCE_RESUME CAN_BCM_RX_CHANGED
CAN_BCM_RX_CHECK_DLC CAN_BCM_RX_DELETE CAN_BCM_RX_FILTER_ID
CAN_BCM_RX_NO_AUTOTIMER CAN_BCM_RX_READ CAN_BCM_RX_RTR_FRAME CAN_BCM_RX_SETUP
CAN_BCM_RX_STATUS CAN_BCM_RX_TIMEOUT CAN_BCM_SETTIMER CAN_BCM_STARTTIMER
CAN_BCM_TX_ANNOUNCE CAN_BCM_TX_COUNTEVT CAN_BCM_TX_CP_CAN_ID CAN_BCM_TX_DELETE
CAN_BCM_TX_EXPIRED CAN_BCM_TX_READ CAN_BCM_TX_RESET_MULTI_IDX CAN_BCM_TX_SEND
CAN_BCM_TX_SETUP CAN_BCM_TX_STATUS
CAN_EFF_FLAG CAN_EFF_MASK CAN_ERR_FLAG CAN_ERR_MASK CAN_ISOTP CAN_J1939 CAN_RAW
CAN_RAW_ERR_FILTER CAN_RAW_FD_FRAMES CAN_RAW_FILTER CAN_RAW_JOIN_FILTERS
CAN_RAW_LOOPBACK CAN_RAW_RECV_OWN_MSGS CAN_RTR_FLAG CAN_SFF_MASK
J1939_EE_INFO_NONE J1939_EE_INFO_TX_ABORT J1939_FILTER_MAX J1939_IDLE_ADDR
J1939_MAX_UNICAST_ADDR J1939_NLA_BYTES_ACKED J1939_NLA_PAD J1939_NO_ADDR
J1939_NO_NAME J1939_NO_PGN J1939_PGN_ADDRESS_CLAIMED
J1939_PGN_ADDRESS_COMMANDED J1939_PGN_MAX J1939_PGN_PDU1_MAX J1939_PGN_REQUEST
ETH_P_ALL ETHERTYPE_ARP ETHERTYPE_IP ETHERTYPE_IPV6 ETHERTYPE_VLAN
UDPLITE_RECV_CSCOV UDPLITE_SEND_CSCOV
TIPC_ADDR_ID TIPC_ADDR_NAME TIPC_ADDR_NAMESEQ TIPC_CFG_SRV TIPC_CLUSTER_SCOPE
TIPC_CONN_TIMEOUT TIPC_CRITICAL_IMPORTANCE TIPC_DEST_DROPPABLE
TIPC_HIGH_IMPORTANCE TIPC_IMPORTANCE TIPC_LOW_IMPORTANCE TIPC_MEDIUM_IMPORTANCE
TIPC_NODE_SCOPE TIPC_PUBLISHED TIPC_SRC_DROPPABLE TIPC_SUBSCR_TIMEOUT
TIPC_SUB_CANCEL TIPC_SUB_PORTS TIPC_SUB_SERVICE TIPC_TOP_SRV TIPC_WAIT_FOREVER
TIPC_WITHDRAWN TIPC_ZONE_SCOPE
VMADDR_CID_ANY VMADDR_CID_HOST VMADDR_PORT_ANY VM_SOCKETS_INVALID_VERSION
POLLIN POLLPRI POLLOUT POLLERR POLLHUP POLLNVAL
POLLRDNORM POLLRDBAND POLLWRNORM POLLWEBAND POLLMSG
FD_READ FD_WRITE FD_ACCEPT FD_CONNECT FD_CLOSE
WSA_WAIT_TIMEOUT WSA_WAIT_FAILED INFINITE
FD_CONNECT_BIT FD_CLOSE_BIT
WSA_IO_PENDING WSA_IO_INCOMPLETE WSA_INVALID_HANDLE
WSA_INVALID_PARAMETER WSA_NOT_ENOUGH_MEMORY WSA_OPERATION_ABORTED
WSA_FLAG_OVERLAPPED WSA_FLAG_NO_HANDLE_INHERIT
SIO_RCVALL SIO_KEEPALIVE_VALS
SIOCGIFNAME SIOCGIFINDEX
SO_DOMAIN SO_PROTOCOL SO_PEERSEC SO_PASSSEC TCP_USER_TIMEOUT TCP_CONGESTION TCP_NOTSENT_LOWAT
'''.split()
for name in constant_names:
setattr(CConfig, name, platform.DefinedConstantInteger(name))
if _WIN32:
# some SDKs define these values with an enum, #ifdef won't work
for name in ('RCVALL_ON', 'RCVALL_OFF', 'RCVALL_SOCKETLEVELONLY', 'TCP_FASTOPEN'):
setattr(CConfig, name, platform.ConstantInteger(name))
constant_names.append(name)
constants["BDADDR_ANY"] = "00:00:00:00:00:00"
constants["BDADDR_LOCAL"] = "00:00:00:FF:FF:FF"
constants_w_defaults = [('SOL_IP', 0),
('SOL_TCP', 6),
('SOL_UDP', 17),
('SOMAXCONN', 5),
('IPPROTO_IP', 6),
('IPPROTO_IPV6', 41),
('IPPROTO_ICMP', 1),
('IPPROTO_TCP', 6),
('IPPROTO_UDP', 17),
('IPPROTO_RAW', 255),
('IPPORT_RESERVED', 1024),
('IPPORT_USERRESERVED', 5000),
('INADDR_ANY', 0x00000000),
('INADDR_BROADCAST', 0xffffffff),
('INADDR_LOOPBACK', 0x7F000001),
('INADDR_UNSPEC_GROUP', 0xe0000000),
('INADDR_ALLHOSTS_GROUP', 0xe0000001),
('INADDR_MAX_LOCAL_GROUP', 0xe00000ff),
('INADDR_NONE', 0xffffffff),
('SHUT_RD', 0),
('SHUT_WR', 1),
('SHUT_RDWR', 2),
('POLLIN', 1),
('POLLPRI', 2),
('POLLOUT', 4),
('POLLERR', 8),
('POLLHUP', 16),
('FD_SETSIZE', 64),
]
for name, default in constants_w_defaults:
setattr(CConfig, name, platform.DefinedConstantInteger(name))
# types
if _MSVC:
socketfd_type = lltype.Unsigned
else:
socketfd_type = rffi.INT_real
CConfig.uint16_t = platform.SimpleType('uint16_t', rffi.USHORT)
CConfig.uint32_t = platform.SimpleType('uint32_t', rffi.UINT)
CConfig.size_t = platform.SimpleType('size_t', rffi.INT)
CConfig.ssize_t = platform.SimpleType('ssize_t', rffi.INT)
CConfig.socklen_t = platform.SimpleType('socklen_t', rffi.UINT_real)
sockaddr_ptr = lltype.Ptr(lltype.ForwardReference())
addrinfo_ptr = lltype.Ptr(lltype.ForwardReference())
# struct types
CConfig.sockaddr = platform.Struct('struct sockaddr',
[('sa_family', rffi.INT),
('sa_data', rffi.CFixedArray(rffi.CHAR, 1)),
])
CConfig.in_addr = platform.Struct('struct in_addr',
[('s_addr', rffi.UINT)])
CConfig.in6_addr = platform.Struct('struct in6_addr',
[('s6_addr', rffi.CFixedArray(rffi.CHAR, 16))])
CConfig.sockaddr_in = platform.Struct('struct sockaddr_in',
[('sin_family', rffi.INT),
('sin_port', rffi.USHORT),
('sin_addr', CConfig.in_addr)])
CConfig.sockaddr_in6 = platform.Struct('struct sockaddr_in6',
[('sin6_family', rffi.INT),
('sin6_port', rffi.USHORT),
('sin6_flowinfo', rffi.INT),
('sin6_addr', CConfig.in6_addr),
('sin6_scope_id', rffi.INT)])
CConfig.sockaddr_un = platform.Struct('struct sockaddr_un',
[('sun_family', rffi.INT),
('sun_path', rffi.CFixedArray(rffi.CHAR, 1))],
ifdef='AF_UNIX')
CConfig.sockaddr_nl = platform.Struct('struct sockaddr_nl',
[('nl_family', rffi.INT),
('nl_pid', rffi.INT),
('nl_groups', rffi.INT)],
ifdef='AF_NETLINK')
CConfig.sockaddr_alg = platform.Struct('struct sockaddr_alg',
[('salg_family', rffi.INT),
('salg_type', rffi.CFixedArray(rffi.CHAR, 14)),
('salg_feat', rffi.SHORT),
('salg_mask', rffi.SHORT),
('salg_name', rffi.CFixedArray(rffi.CHAR, 64)),
], ifdef='AF_ALG')
CConfig.sockaddr_qrtr = platform.Struct('struct sockaddr_qrtr',
[('sq_family', rffi.INT),
('sq_node', rffi.INT),
('sq_port', rffi.INT),
], ifdef='AF_QIPCRTR')
CConfig.addrinfo = platform.Struct('struct addrinfo',
[('ai_flags', rffi.INT),
('ai_family', rffi.INT),
('ai_socktype', rffi.INT),
('ai_protocol', rffi.INT),
('ai_addrlen', rffi.INT),
('ai_addr', sockaddr_ptr),
('ai_canonname', CCHARP),
('ai_next', addrinfo_ptr)])
CConfig.hostent = platform.Struct('struct hostent',
[('h_name', CCHARP),
('h_aliases', rffi.CCHARPP),
('h_addrtype', rffi.INT),
('h_length', rffi.INT),
('h_addr_list', rffi.CCHARPP),
])
CConfig.servent = platform.Struct('struct servent',
[('s_name', CCHARP),
('s_port', rffi.INT),
('s_proto', CCHARP),
])
CConfig.protoent = platform.Struct('struct protoent',
[('p_proto', rffi.INT),
])
CConfig.HAVE_ACCEPT4 = platform.Has('accept4')
if _POSIX:
CConfig.nfds_t = platform.SimpleType('nfds_t')
CConfig.pollfd = platform.Struct('struct pollfd',
[('fd', socketfd_type),
('events', rffi.SHORT),
('revents', rffi.SHORT)])
CConfig.if_nameindex_s = platform.Struct('struct if_nameindex',
[('if_index', rffi.UINT),
('if_name', rffi.CCHARP)])
if _HAS_AF_PACKET:
CConfig.sockaddr_ll = platform.Struct('struct sockaddr_ll',
[('sll_family', rffi.INT),
('sll_ifindex', rffi.INT),
('sll_protocol', rffi.INT),
('sll_pkttype', rffi.INT),
('sll_hatype', rffi.INT),
('sll_addr', rffi.CFixedArray(rffi.UCHAR, 8)),
('sll_halen', rffi.INT)])
CConfig.ifreq = platform.Struct('struct ifreq',
[('ifr_ifindex', rffi.INT),
('ifr_name', rffi.CFixedArray(rffi.CHAR, 8))])
else:
CConfig.if_nameindex_s = rffi.CStruct('if_nameindex',
('if_index', rffi.UINT),
('if_name', rffi.CCHARP))
includes = []
separate_module_sources = []
post_include_bits = []
# insert handler for sendmsg / recvmsg here
HAVE_SENDMSG = bool(_POSIX)
if HAVE_SENDMSG:
includes += ['stddef.h',
'sys/socket.h',
'unistd.h',
'string.h',
'stdlib.h',
'errno.h',
'limits.h',
'stdio.h',
'sys/types.h',
'netinet/in.h',
'arpa/inet.h']
separate_module_sources += ['''
// special defines for returning from recvmsg
#define BAD_MSG_SIZE_GIVEN -10000
#define BAD_ANC_SIZE_GIVEN -10001
#define MAL_ANC -10002
// special defines for returning from sendmsg
#define MUL_MSGS_NOT_SUP -1000
#define ANC_DATA_TOO_LARGE -1001
#define ANC_DATA_TOO_LARGEX -1002
#if INT_MAX > 0x7fffffff
#define SOCKLEN_T_LIMIT 0x7fffffff
#else
#define SOCKLEN_T_LIMIT INT_MAX
#endif
// #########################################################################
// Recvmsg implementation and associated functions
// Taken from CPython. Determines the minimum memory space required for the ancillary data.
#ifdef CMSG_SPACE
static int
cmsg_min_space(struct msghdr *msg, struct cmsghdr *cmsgh, size_t space)
{
size_t cmsg_offset;
static const size_t cmsg_len_end = (offsetof(struct cmsghdr, cmsg_len) +
sizeof(cmsgh->cmsg_len));
/* Note that POSIX allows msg_controllen to be of signed type. */
if (cmsgh == NULL || msg->msg_control == NULL)
return 0;
/* Note that POSIX allows msg_controllen to be of a signed type. This is
annoying under OS X as it's unsigned there and so it triggers a
tautological comparison warning under Clang when compared against 0.
Since the check is valid on other platforms, silence the warning under
Clang. */
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wtautological-compare"
#endif
#if defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5)))
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wtype-limits"
#endif
if (msg->msg_controllen < 0)
return 0;
#if defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5)))
#pragma GCC diagnostic pop
#endif
#ifdef __clang__
#pragma clang diagnostic pop
#endif
if (space < cmsg_len_end)
space = cmsg_len_end;
cmsg_offset = (char *)cmsgh - (char *)msg->msg_control;
return (cmsg_offset <= (size_t)-1 - space &&
cmsg_offset + space <= msg->msg_controllen);
}
#endif
// Taken from CPython.
#ifdef CMSG_LEN
/* If pointer CMSG_DATA(cmsgh) is in buffer msg->msg_control, set
*space to number of bytes following it in the buffer and return
true; otherwise, return false. Assumes cmsgh, msg->msg_control and
msg->msg_controllen are valid. */
static int
get_cmsg_data_space(struct msghdr *msg, struct cmsghdr *cmsgh, size_t *space)
{
size_t data_offset;
char *data_ptr;
if ((data_ptr = (char *)CMSG_DATA(cmsgh)) == NULL)
return 0;
data_offset = data_ptr - (char *)msg->msg_control;
if (data_offset > msg->msg_controllen)
return 0;
*space = msg->msg_controllen - data_offset;
return 1;
}
// Taken from CPython.
/* If cmsgh is invalid or not contained in the buffer pointed to by
msg->msg_control, return -1. If cmsgh is valid and its associated
data is entirely contained in the buffer, set *data_len to the
length of the associated data and return 0. If only part of the
associated data is contained in the buffer but cmsgh is otherwise
valid, set *data_len to the length contained in the buffer and
return 1. */
static int
get_cmsg_data_len(struct msghdr *msg, struct cmsghdr *cmsgh, size_t *data_len)
{
size_t space, cmsg_data_len;
if (!cmsg_min_space(msg, cmsgh, CMSG_LEN(0)) ||
cmsgh->cmsg_len < CMSG_LEN(0))
return -1;
cmsg_data_len = cmsgh->cmsg_len - CMSG_LEN(0);
if (!get_cmsg_data_space(msg, cmsgh, &space))
return -1;
if (space >= cmsg_data_len) {
*data_len = cmsg_data_len;
return 0;
}
*data_len = space;
return 1;
}
#endif /* CMSG_LEN */
/*
Structure meant to hold the information received after a recvmsg is performed.
Essentially it holds: the address, the message, the ancillary data and the return flags.
I use this structure for 2 main reasons:
- keep things ordered
- some of the ancillary parameters need to be int not long (rffi SignedP is actually long*),
therefore I cannot use the parameters directly
*/
struct recvmsg_info
{
struct sockaddr* address; // address fields
socklen_t addrlen;
int size_of_ancillary; // ancillary fields
int* levels;
int* types;
char** file_descr;
int* descr_per_ancillary;
int retflag; // return flag field
};
/*
Wrapper function over recvmsg. Since it returns a lot of data,
in a structure that is hard to parse in rffi, it was implemented in C.
All the parameters, save the socket fd, message_size, ancillary_size
will be malloc'd and/or modified.
*/
RPY_EXTERN
int recvmsg_implementation(
int socket_fd,
int ancillary_size,
int flags,
struct sockaddr* address,
socklen_t* addrlen,
int* message_lengths,
char** messages,
int no_of_messages,
long* size_of_ancillary,
long** levels,
long** types,
char** file_descr,
long** descr_per_ancillary,
long* retflag)
{
struct sockaddr* recvd_address;
socklen_t recvd_addrlen;
struct msghdr msg = {0};
void *controlbuf = NULL;
struct cmsghdr *cmsgh;
int cmsg_status;
struct recvmsg_info* retinfo;
int error_flag = 0; // variable to be set in case of special errors.
int cmsgdatalen = 0;
size_t i;
// variables that are set to 1, if the message charp has been allocated
// and if the ancillary variables have been allocated. To be used in case of failure.
int iov_alloc = 0;
int anc_alloc = 0;
retinfo = (struct recvmsg_info*) malloc(sizeof(struct recvmsg_info));
if (ancillary_size > SOCKLEN_T_LIMIT){
error_flag = BAD_ANC_SIZE_GIVEN;
goto fail;
}
// Add the message
struct iovec *iovs = NULL;
if (no_of_messages > 0) {
iovs = (struct iovec*) malloc(no_of_messages * sizeof(struct iovec));
memset(iovs, 0, no_of_messages * sizeof(struct iovec));
for (i=0; i < no_of_messages; i++) {
iovs[i].iov_base = messages[i];
iovs[i].iov_len = message_lengths[i];
}
}
// Setup the ancillary buffer memory
controlbuf = malloc(ancillary_size);
// Setup the recv address memory
recvd_addrlen = sizeof(struct sockaddr_storage);
recvd_address = (struct sockaddr*) malloc(recvd_addrlen);
memset(recvd_address, 0,recvd_addrlen);
// Setup the msghdr struct
msg.msg_name = recvd_address;
msg.msg_namelen = recvd_addrlen;
msg.msg_iov = iovs;
msg.msg_iovlen = no_of_messages;
msg.msg_control = controlbuf;
msg.msg_controllen = ancillary_size;
// Link my structure to the msghdr fields
retinfo->address = msg.msg_name;
iov_alloc = 1;
ssize_t bytes_recvd = 0;
bytes_recvd = recvmsg(socket_fd, &msg, flags);
if (bytes_recvd < 0){
goto fail;
}
retinfo->addrlen = (socklen_t) msg.msg_namelen;
// Count the ancillary items & allocate the memory
int anc_counter = 0;
for (cmsgh = ((msg.msg_controllen > 0) ? CMSG_FIRSTHDR(&msg) : NULL);
cmsgh != NULL; cmsgh = CMSG_NXTHDR(&msg, cmsgh)) {
anc_counter++;
}
retinfo->size_of_ancillary = anc_counter;
retinfo->file_descr = (char**) malloc (anc_counter * sizeof(char*));
retinfo->levels = (int*) malloc(anc_counter * sizeof(int));
retinfo->types = (int*) malloc(anc_counter * sizeof(int));
retinfo->descr_per_ancillary = (int*) malloc(anc_counter * sizeof(int));
anc_alloc = 1;
// Extract the ancillary items
i=0;
for (cmsgh = ((msg.msg_controllen > 0) ? CMSG_FIRSTHDR(&msg) : NULL);
cmsgh != NULL; cmsgh = CMSG_NXTHDR(&msg, cmsgh)) {
size_t local_size = 0;
cmsg_status = get_cmsg_data_len(&msg, cmsgh, &local_size);
if (cmsg_status !=0 ){
error_flag = MAL_ANC;
goto err_closefds;
}
retinfo->file_descr[i] = (char*) malloc(local_size);
memcpy(retinfo->file_descr[i], CMSG_DATA(cmsgh), local_size);
retinfo->levels[i] = cmsgh->cmsg_level;
retinfo->types[i] = cmsgh->cmsg_type;
retinfo->descr_per_ancillary[i] =local_size;
i++;
}
retinfo->retflag = msg.msg_flags;
// Set the parameters of address
memcpy(address,retinfo->address,retinfo->addrlen);
*addrlen = retinfo->addrlen;
// Set the parameters of message
size_of_ancillary[0] = retinfo->size_of_ancillary;
// Set the parameters of ancillary
*levels = (long*) malloc (sizeof(long) * retinfo->size_of_ancillary);
*types = (long*) malloc (sizeof(long) * retinfo->size_of_ancillary);
*descr_per_ancillary = (long*) malloc (sizeof(long) * retinfo->size_of_ancillary);
int counter = 0;
for (i=0; i < retinfo->size_of_ancillary; i++){
counter += retinfo->descr_per_ancillary[i];
// Convert the int* to long*
levels[0][i] = (long) retinfo->levels[i];
types[0][i] = (long) retinfo->types[i];
descr_per_ancillary[0][i] = (long) retinfo->descr_per_ancillary[i];
}
*file_descr = (char*) malloc (sizeof(char) * counter);
memset(*file_descr, 0, sizeof(char) * counter);
counter = 0;
for (i=0; i<retinfo->size_of_ancillary; i++){
memcpy(*file_descr+counter,retinfo->file_descr[i], retinfo->descr_per_ancillary[i]);
counter += retinfo->descr_per_ancillary[i];
}
// Set the retflag
retflag[0] = retinfo->retflag;
// Free the memory
free(retinfo->address);
free(retinfo->levels);
free(retinfo->types);
free(retinfo->descr_per_ancillary);
for (i = 0; i < retinfo->size_of_ancillary; i++)
free(retinfo->file_descr[i]);
free(retinfo->file_descr);
free(retinfo);
free(controlbuf);
if (iovs != NULL)
free(iovs);
return bytes_recvd;
fail:
if (anc_alloc){
free(retinfo->file_descr);
free(retinfo->levels);
free(retinfo->types);
free(retinfo->descr_per_ancillary);
free(retinfo->address);
free(retinfo);
free(controlbuf);
}else{
if (iov_alloc){
free(retinfo->address);
free(controlbuf);
free(retinfo);
}
}
if (iovs != NULL)
free(iovs);
if (error_flag==0) error_flag = -1;
return error_flag;
err_closefds:
// Special case for UNIX sockets. In case file descriptors are received, they need to be closed.
// Taken from CPython
#ifdef SCM_RIGHTS
/* Close all descriptors coming from SCM_RIGHTS, so they don't leak. */
for (cmsgh = ((msg.msg_controllen > 0) ? CMSG_FIRSTHDR(&msg) : NULL);
cmsgh != NULL; cmsgh = CMSG_NXTHDR(&msg, cmsgh)) {
size_t dataleng;
cmsg_status = get_cmsg_data_len(&msg, cmsgh, &dataleng);
cmsgdatalen = (int) dataleng;
if (cmsg_status < 0)
break;
if (cmsgh->cmsg_level == SOL_SOCKET &&
cmsgh->cmsg_type == SCM_RIGHTS) {
size_t numfds;
int *fdp;
numfds = cmsgdatalen / sizeof(int);
fdp = (int *)CMSG_DATA(cmsgh);
while (numfds-- > 0)
close(*fdp++);
}
if (cmsg_status != 0)
break;
}
#endif /* SCM_RIGHTS */
goto fail;
}
// ##########################################################################
// Sendmsg implementation and associated functions
#ifdef CMSG_LEN
static int
get_CMSG_LEN(size_t length, size_t *result)
{
size_t tmp;
if (length > (SOCKLEN_T_LIMIT - CMSG_LEN(0)))
return 0;
tmp = CMSG_LEN(length);
if ((tmp > SOCKLEN_T_LIMIT) || (tmp < length))
return 0;
*result = tmp;
return 1;
}
#endif
#ifdef CMSG_SPACE
/* If length is in range, set *result to CMSG_SPACE(length) and return
true; otherwise, return false. */
static int
get_CMSG_SPACE(size_t length, size_t *result)
{
size_t tmp;
/* Use CMSG_SPACE(1) here in order to take account of the padding
necessary before *and* after the data. */
if (length > (SOCKLEN_T_LIMIT - CMSG_SPACE(1)))
return 0;
tmp = CMSG_SPACE(length);
if ((tmp > SOCKLEN_T_LIMIT) || (tmp < length))
return 0;
*result = tmp;
return 1;
}
#endif
/*
sendmsg_implementation is a wrapper over sendmsg of the API.
It was inspired from the way CPython did their implementation of this.
The main reason that it was written in C, is the struct msghdr,
which contains the ancillary data in a linked list of cmsghdr structures.
It was simpler to use it in C, and then push the simpler types of data via rffi.
*/
RPY_EXTERN
int sendmsg_implementation
(int socket,
struct sockaddr* address,
socklen_t addrlen,
long* length_of_messages,
char** messages,
int no_of_messages,
long* levels,
long* types,
char** file_descriptors,
long* no_of_fds,
int control_length,
int flag
)
{
struct msghdr msg = {0};
struct cmsghdr *cmsg;
void* controlbuf = NULL;
int retval;
size_t i;
// Prepare the msghdr structure for the send:
// Add the address
if (address != NULL) {
msg.msg_name = address;
msg.msg_namelen = addrlen;
}
// Add the message
struct iovec *iovs = NULL;
if (no_of_messages > 0){
iovs = (struct iovec*) malloc(no_of_messages * sizeof(struct iovec));
memset(iovs, 0, no_of_messages * sizeof(struct iovec));
msg.msg_iov = iovs;
msg.msg_iovlen = no_of_messages;
for (i=0; i < no_of_messages; i++){
iovs[i].iov_base = messages[i];
iovs[i].iov_len = length_of_messages[i];
}
}
// Add the ancillary
#ifndef CMSG_SPACE
if (control_length > 1){
free(iovs);
return MUL_MSGS_NOT_SUP;
}
#endif
if (control_length > 0){
//compute the total size of the ancillary
//getting the exact amount of space can be tricky and os dependent.
size_t total_size_of_ancillary = 0;
size_t space;
size_t controllen = 0, controllen_last = 0;
for (i = 0; i< control_length; i++){
total_size_of_ancillary = no_of_fds[i];
#ifdef CMSG_SPACE
if (!get_CMSG_SPACE(total_size_of_ancillary, &space)) {
#else
if (!get_CMSG_LEN(total_size_of_ancillary, &space)) {
#endif
if (iovs != NULL)
free(iovs);
return ANC_DATA_TOO_LARGE;
}
controllen +=space;
if ((controllen > SOCKLEN_T_LIMIT) || (controllen < controllen_last)) {
if (iovs != NULL)
free(iovs);
return ANC_DATA_TOO_LARGEX;
}
controllen_last = controllen;
}
controlbuf = malloc(controllen);
msg.msg_control = controlbuf;
msg.msg_controllen = controllen;
// memset controlbuf to 0 to avoid trash in the ancillary
memset(controlbuf, 0, controllen);
cmsg = NULL;
for (i = 0; i < control_length; i++) {
cmsg = (i == 0) ? CMSG_FIRSTHDR(&msg) : CMSG_NXTHDR(&msg, cmsg);
cmsg->cmsg_level = (int) levels[i];
cmsg->cmsg_type = (int) types[i];
cmsg->cmsg_len = CMSG_LEN(sizeof(char) * no_of_fds[i]);
memcpy(CMSG_DATA(cmsg), file_descriptors[i], sizeof(char) * no_of_fds[i]);
}
}
// Add the flags
msg.msg_flags = flag;
// Send the data
retval = sendmsg(socket, &msg, flag);
// free everything that was allocated here, and we would not need in rsocket
if (iovs != NULL)
free(iovs);
if (controlbuf !=NULL)
free(controlbuf);
return retval;
}
// ############################################################################
// Wrappers for CMSG_SPACE and CMSG_LEN
/*
These 2 functions are wrappers over sys/socket.h's CMSG_SPACE and CMSG_LEN.
They are identical to CPython's.
*/
#ifdef CMSG_SPACE
RPY_EXTERN
size_t CMSG_SPACE_wrapper(size_t desired_space){
size_t result;
if (!get_CMSG_SPACE(desired_space, &result)){
return 0;
}
return result;
}
#endif
#ifdef CMSG_LEN
RPY_EXTERN
size_t CMSG_LEN_wrapper(size_t desired_len){
size_t result;
if (!get_CMSG_LEN(desired_len, &result)){
return 0;
}
return result;
}
#endif
// ###########################################################################
// Extra functions that I needed
/*
This function is used to memcpy from a char* at an offset.
Could not get rffi.c_memcpy to do it at an offset, so I made my own.
*/
RPY_EXTERN
int memcpy_from_CCHARP_at_offset_and_size(char* stringfrom, char** stringto, int offset, int size){
*stringto = memcpy(*stringto, stringfrom + offset, size);
return 0;
}
/*
These functions free memory that was allocated in C (sendmsg or recvmsg) was used in rsocket and now needs cleanup
*/
RPY_EXTERN
int free_pointer_to_signedp(long** ptrtofree){
free(*ptrtofree);
return 0;
}
RPY_EXTERN
int free_ptr_to_charp(char** ptrtofree){
free(*ptrtofree);
return 0;
}
''',]
post_include_bits +=[ "RPY_EXTERN "
"int sendmsg_implementation(int socket, struct sockaddr* address, socklen_t addrlen, long* length_of_messages, char** messages, int no_of_messages, long* levels, long* types, char** file_descriptors, long* no_of_fds, int control_length, int flag );\n"
"RPY_EXTERN "
"int recvmsg_implementation(int socket_fd, int ancillary_size, int flags, struct sockaddr* address, socklen_t* addrlen, int* message_lengths, char** messages, int no_of_messages, long* size_of_ancillary, long** levels, long** types, char** file_descr, long** descr_per_ancillary, long* flag);\n"
"static "
"int cmsg_min_space(struct msghdr *msg, struct cmsghdr *cmsgh, size_t space);\n"
"static "
"int get_cmsg_data_space(struct msghdr *msg, struct cmsghdr *cmsgh, size_t *space);\n"
"static "
"int get_cmsg_data_len(struct msghdr *msg, struct cmsghdr *cmsgh, size_t *data_len);\n"
"static "
"int get_CMSG_LEN(size_t length, size_t *result);\n"
"static "
"int get_CMSG_SPACE(size_t length, size_t *result);\n"
"RPY_EXTERN "
"size_t CMSG_LEN_wrapper(size_t desired_len);\n"
"RPY_EXTERN "
"size_t CMSG_SPACE_wrapper(size_t desired_space);\n"
"RPY_EXTERN "
"int memcpy_from_CCHARP_at_offset_and_size(char* stringfrom, char** stringto, int offset, int size);\n"
"RPY_EXTERN "
"int free_pointer_to_signedp(long** ptrtofree);\n"
"RPY_EXTERN "
"int free_ptr_to_charp(char** ptrtofree);\n"
]
if _WIN32:
CConfig.WSAEVENT = platform.SimpleType('WSAEVENT', rffi.VOIDP)
CConfig.WSANETWORKEVENTS = platform.Struct(
'struct _WSANETWORKEVENTS',
[('lNetworkEvents', rffi.LONG),
('iErrorCode', rffi.CFixedArray(rffi.INT, 10)), #FD_MAX_EVENTS
])
CConfig.WSAPROTOCOL_INFO = platform.Struct(
'WSAPROTOCOL_INFOA',
[]) # Struct is just passed between functions
CConfig.FROM_PROTOCOL_INFO = platform.DefinedConstantInteger(
'FROM_PROTOCOL_INFO')
post_include_bits +=[dedent("""\
struct if_nameindex {
unsigned int if_index;
char * if_name;
};
RPY_EXTERN struct if_nameindex * if_nameindex(void);
RPY_EXTERN void if_freenameindex(struct if_nameindex *ptr);
""")]
separate_module_sources += [dedent("""\
#include <Iphlpapi.h>
#include <stdlib.h>
RPY_EXTERN
struct if_nameindex * if_nameindex(void) {
PMIB_IF_TABLE2 tbl;
int ret;
if (GetIfTable2Ex(MibIfTableRaw, &tbl) != NO_ERROR) {
return NULL;
}
size_t memsize = sizeof(struct if_nameindex) * (tbl->NumEntries + 1);
struct if_nameindex *out = malloc(memsize);
if (out == NULL) {
return NULL;
}
ULONG i = 0;
for (i; i < tbl->NumEntries; i++) {
MIB_IF_ROW2 r = tbl->Table[i];
WCHAR buf[NDIS_IF_MAX_STRING_SIZE + 1];
if ((ret = ConvertInterfaceLuidToNameW(&r.InterfaceLuid, buf,
NDIS_IF_MAX_STRING_SIZE))) {
FreeMibTable(tbl);
for (ULONG j=0; j<i; j++) {
free(out[j].if_name);
}
free(out);
return NULL;
}
/* convert from wchar_t to char */
size_t origsize = wcslen(buf) + 1;
size_t newsize = origsize * 2 + 2;
size_t convertedChars = 0;
out[i].if_name = malloc(newsize);
out[i].if_name[0] = '\\0';
wcstombs_s(&convertedChars, out[i].if_name, newsize, buf, newsize - 1);
out[i].if_index = r.InterfaceIndex;
}
out[i].if_name = NULL;
out[i].if_index = 0;
return out;
}
RPY_EXTERN
void if_freenameindex(struct if_nameindex *ptr) {
if (ptr == NULL) return;
int index = 0;
while (1) {
if (ptr[index].if_name == NULL) break;
free(ptr[index].if_name);
index += 1;
}
free(ptr);
}""")]
compilation_info = eci.merge(ExternalCompilationInfo(
includes=includes,
separate_module_sources=separate_module_sources,
post_include_bits=post_include_bits,
))
CConfig.timeval = platform.Struct('struct timeval',
[('tv_sec', rffi.LONG),
('tv_usec', rffi.LONG)])
fd_set = rffi.COpaquePtr('fd_set', compilation_info=eci)
if _WIN32:
CConfig.WSAData = platform.Struct('struct WSAData',
[('wVersion', rffi.USHORT),
('wHighVersion', rffi.USHORT),
('szDescription', rffi.CFixedArray(lltype.Char, 1)), # (WSADESCRIPTION_LEN+1)
('szSystemStatus', rffi.CFixedArray(lltype.Char, 1)), # (WSASYS_STATUS_LEN+1)
('iMaxSockets', rffi.USHORT),
('iMaxUdpDg', rffi.USHORT),
('lpVendorInfo', CCHARP)])
CConfig.tcp_keepalive = platform.Struct(
'struct tcp_keepalive',
[('onoff', rffi.ULONG),
('keepalivetime', rffi.ULONG),
('keepaliveinterval', rffi.ULONG)])
CConfig.GUID = platform.Struct(
'struct _GUID',
[('Data1', rffi.UINT),
('Data2', rffi.UINT),
('Data3', rffi.UINT),
('Data4', rffi.CFixedArray(rffi.UCHAR, 8))
])
CConfig.WSAPROTOCOLCHAIN = platform.Struct(
'struct _WSAPROTOCOLCHAIN',
[('ChainLen', rffi.INT),
('ChainEntries', rffi.CFixedArray(rffi.UINT, 7))])
WSAPROTOCOLCHAIN = CConfig.WSAPROTOCOLCHAIN
GUID = CConfig.GUID
CConfig.WSAPROTOCOL_INFOW = platform.Struct(
'struct _WSAPROTOCOL_INFOW',
[('dwServiceFlags1', rffi.UINT),
('dwServiceFlags2', rffi.UINT),
('dwServiceFlags3', rffi.UINT),
('dwServiceFlags4', rffi.UINT),
('dwProviderFlags', rffi.UINT),
('ProviderId', GUID),
('dwCatalogEntryId', rffi.UINT),
('ProtocolChain', WSAPROTOCOLCHAIN),
('iVersion', rffi.INT),
('iAddressFamily', rffi.INT),
('iMaxSockAddr', rffi.INT),
('iMinSockAddr', rffi.INT),
('iSocketType', rffi.INT),
('iProtocol', rffi.INT),
('iProtocolMaxOffset', rffi.INT),
('iNetworkByteOrder', rffi.INT),
('iSecurityScheme', rffi.INT),
('dwMessageSize', rffi.UINT),
('dwProviderReserved', rffi.UINT),
('szProtocol', rffi.CFixedArray(rffi.UCHAR, 256))])
class cConfig:
pass
cConfig.__dict__.update(platform.configure(CConfig))
sockaddr_ptr.TO.become(cConfig.sockaddr)
addrinfo_ptr.TO.become(cConfig.addrinfo)
# fill in missing constants with reasonable defaults
cConfig.NI_MAXHOST = cConfig.NI_MAXHOST or 1025
cConfig.NI_MAXSERV = cConfig.NI_MAXSERV or 32
cConfig.INET_ADDRSTRLEN = cConfig.INET_ADDRSTRLEN or 16
for name in constant_names:
value = getattr(cConfig, name)
if value is not None:
constants[name] = value
for name, default in constants_w_defaults:
value = getattr(cConfig, name)
if value is not None:
constants[name] = value
else:
constants[name] = default
if not _HAS_AF_PACKET and 'AF_PACKET' in constants:
del constants['AF_PACKET']
constants['has_ipv6'] = True # This is a configuration option in CPython
for name, value in constants.items():
if isinstance(value, long):
if r_uint(value) == value:
constants[name] = intmask(value)
locals().update(constants)
O_RDONLY = cConfig.O_RDONLY
O_WRONLY = cConfig.O_WRONLY
O_RDWR = cConfig.O_RDWR
O_NONBLOCK = cConfig.O_NONBLOCK
F_GETFL = cConfig.F_GETFL
F_SETFL = cConfig.F_SETFL
FIONBIO = cConfig.FIONBIO
INET_ADDRSTRLEN = cConfig.INET_ADDRSTRLEN
INET6_ADDRSTRLEN = cConfig.INET6_ADDRSTRLEN
EINTR = cConfig.EINTR or cConfig.WSAEINTR
EINPROGRESS = cConfig.EINPROGRESS or cConfig.WSAEINPROGRESS
EWOULDBLOCK = cConfig.EWOULDBLOCK or cConfig.WSAEWOULDBLOCK
EAFNOSUPPORT = cConfig.EAFNOSUPPORT or cConfig.WSAEAFNOSUPPORT
# vs 2010 and above define both the constansts
WSAEINPROGRESS = cConfig.WSAEINPROGRESS or cConfig.EINPROGRESS
WSAEWOULDBLOCK = cConfig.WSAEWOULDBLOCK or cConfig.EWOULDBLOCK
WSAEAFNOSUPPORT = cConfig.WSAEAFNOSUPPORT or cConfig.EAFNOSUPPORT
EISCONN = cConfig.EISCONN or cConfig.WSAEISCONN
PIPE_BUF = cConfig.PIPE_BUF # may be None
linux = cConfig.linux
WIN32 = cConfig.WIN32
assert WIN32 == _WIN32
if _MSVC:
def invalid_socket(fd):
return widen(fd) == INVALID_SOCKET
INVALID_SOCKET = r_uint(cConfig.INVALID_SOCKET)
else:
def invalid_socket(fd):
return widen(fd) < 0
INVALID_SOCKET = -1
uint16_t = cConfig.uint16_t
uint32_t = cConfig.uint32_t
size_t = cConfig.size_t
ssize_t = cConfig.ssize_t
socklen_t = cConfig.socklen_t
sockaddr = cConfig.sockaddr
#sockaddr_size = sizeof(sockaddr)
sockaddr_in = cConfig.sockaddr_in
sockaddr_in6 = cConfig.sockaddr_in6
sockaddr_un = cConfig.sockaddr_un
if cConfig.sockaddr_nl is not None:
sockaddr_nl = cConfig.sockaddr_nl
if cConfig.sockaddr_alg is not None:
sockaddr_alg = cConfig.sockaddr_alg
if cConfig.sockaddr_qrtr is not None:
sockaddr_qrtr = cConfig.sockaddr_qrtr
in_addr = cConfig.in_addr
#in_addr_size = sizeof(in_addr)
in6_addr = cConfig.in6_addr
addrinfo = cConfig.addrinfo
if _POSIX:
nfds_t = cConfig.nfds_t
pollfd = cConfig.pollfd
if _HAS_AF_PACKET:
sockaddr_ll = cConfig.sockaddr_ll
ifreq = cConfig.ifreq
if_nameindex_s = cConfig.if_nameindex_s
if WIN32:
WSAEVENT = cConfig.WSAEVENT
WSANETWORKEVENTS = cConfig.WSANETWORKEVENTS
SAVE_ERR = rffi.RFFI_SAVE_WSALASTERROR
if_nameindex_s = CConfig.if_nameindex_s
else:
SAVE_ERR = rffi.RFFI_SAVE_ERRNO
timeval = cConfig.timeval
def external(name, args, result, **kwds):
return rffi.llexternal(name, args, result, compilation_info=eci,
calling_conv=calling_conv, **kwds)
def external_c(name, args, result, **kwargs):
return rffi.llexternal(name, args, result, compilation_info=eci,
calling_conv='c', **kwargs)
if _POSIX:
dup = external('dup', [socketfd_type], socketfd_type, save_err=SAVE_ERR)
gai_strerror = external('gai_strerror', [rffi.INT], CONST_CCHARP)
#h_errno = c_int.in_dll(socketdll, 'h_errno')
#
#hstrerror = socketdll.hstrerror
#hstrerror.argtypes = [c_int]
#hstrerror.restype = c_char_p
socket = external('socket', [rffi.INT, rffi.INT, rffi.INT], socketfd_type,
save_err=SAVE_ERR)
if WIN32:
socketclosename = 'closesocket'
else:
socketclosename = 'close'
socketclose = external(socketclosename, [socketfd_type], rffi.INT,
releasegil=False, save_err=SAVE_ERR)
socketclose_no_errno = external(socketclosename, [socketfd_type], rffi.INT,
releasegil=False)
socketconnect = external('connect', [socketfd_type, sockaddr_ptr, socklen_t],
rffi.INT, save_err=SAVE_ERR)
getaddrinfo = external('getaddrinfo', [CCHARP, CCHARP,
addrinfo_ptr,
lltype.Ptr(rffi.CArray(addrinfo_ptr))], rffi.INT)
freeaddrinfo = external('freeaddrinfo', [addrinfo_ptr], lltype.Void)
getnameinfo = external('getnameinfo', [sockaddr_ptr, socklen_t, CCHARP,
size_t, CCHARP, size_t, rffi.INT], rffi.INT)
if sys.platform.startswith("openbsd") or sys.platform.startswith("darwin"):
htonl = external('htonl', [rffi.UINT], rffi.UINT, releasegil=False, macro=True)
htons = external('htons', [rffi.USHORT], rffi.USHORT, releasegil=False, macro=True)
ntohl = external('ntohl', [rffi.UINT], rffi.UINT, releasegil=False, macro=True)
ntohs = external('ntohs', [rffi.USHORT], rffi.USHORT, releasegil=False, macro=True)
else:
htonl = external('htonl', [rffi.UINT], rffi.UINT, releasegil=False)
htons = external('htons', [rffi.USHORT], rffi.USHORT, releasegil=False)
ntohl = external('ntohl', [rffi.UINT], rffi.UINT, releasegil=False)
ntohs = external('ntohs', [rffi.USHORT], rffi.USHORT, releasegil=False)
if _POSIX:
inet_aton = external('inet_aton', [CCHARP, lltype.Ptr(in_addr)],
rffi.INT)
inet_ntoa = external('inet_ntoa', [in_addr], rffi.CCHARP)
inet_pton = external('inet_pton', [rffi.INT, rffi.CCHARP,
rffi.VOIDP], rffi.INT,
save_err=SAVE_ERR)
inet_ntop = external('inet_ntop', [rffi.INT, rffi.VOIDP, CCHARP,
socklen_t], CONST_CCHARP,
save_err=SAVE_ERR)
inet_addr = external('inet_addr', [rffi.CCHARP], rffi.UINT)
socklen_t_ptr = lltype.Ptr(rffi.CFixedArray(socklen_t, 1))
socketaccept = external('accept', [socketfd_type, sockaddr_ptr,
socklen_t_ptr], socketfd_type,
save_err=SAVE_ERR)
HAVE_ACCEPT4 = cConfig.HAVE_ACCEPT4
if HAVE_ACCEPT4:
socketaccept4 = external('accept4', [socketfd_type, sockaddr_ptr,
socklen_t_ptr, rffi.INT],
socketfd_type,
save_err=SAVE_ERR)
socketbind = external('bind', [socketfd_type, sockaddr_ptr, socklen_t],
rffi.INT, save_err=SAVE_ERR)
socketlisten = external('listen', [socketfd_type, rffi.INT], rffi.INT,
save_err=SAVE_ERR)
socketgetpeername = external('getpeername', [socketfd_type,
sockaddr_ptr, socklen_t_ptr], rffi.INT,
save_err=SAVE_ERR)
socketgetsockname = external('getsockname', [socketfd_type,
sockaddr_ptr, socklen_t_ptr], rffi.INT,
save_err=SAVE_ERR)
socketgetsockopt = external('getsockopt', [socketfd_type, rffi.INT,
rffi.INT, rffi.VOIDP, socklen_t_ptr], rffi.INT,
save_err=SAVE_ERR)
socketsetsockopt = external('setsockopt', [socketfd_type, rffi.INT,
rffi.INT, rffi.VOIDP, socklen_t], rffi.INT,
save_err=SAVE_ERR)
if WIN32:
socketrecv = external('recv', [socketfd_type, rffi.VOIDP, rffi.INT,
rffi.INT], rffi.INT, save_err=SAVE_ERR)
else:
socketrecv = external('recv', [socketfd_type, rffi.VOIDP, rffi.INT,
rffi.INT], ssize_t, save_err=SAVE_ERR)
recvfrom = external('recvfrom', [socketfd_type, rffi.VOIDP, size_t,
rffi.INT, sockaddr_ptr, socklen_t_ptr], rffi.INT,
save_err=SAVE_ERR)
recvmsg = jit.dont_look_inside(rffi.llexternal(
"recvmsg_implementation",
[rffi.INT, rffi.INT, rffi.INT, sockaddr_ptr, socklen_t_ptr,
rffi.INT_realP, rffi.CCHARPP, rffi.INT, rffi.SIGNEDP, rffi.SIGNEDPP, rffi.SIGNEDPP,
rffi.CCHARPP, rffi.SIGNEDPP, rffi.SIGNEDP], rffi.INT,
save_err=SAVE_ERR, compilation_info=compilation_info))
memcpy_from_CCHARP_at_offset = jit.dont_look_inside(rffi.llexternal("memcpy_from_CCHARP_at_offset_and_size",
[rffi.CCHARP, rffi.CCHARPP,rffi.INT,rffi.INT],rffi.INT,save_err=SAVE_ERR,compilation_info=compilation_info))
freeccharp = jit.dont_look_inside(rffi.llexternal("free_ptr_to_charp",
[rffi.CCHARPP],rffi.INT,save_err=SAVE_ERR,compilation_info=compilation_info))
freesignedp = jit.dont_look_inside(rffi.llexternal("free_pointer_to_signedp",
[rffi.SIGNEDPP],rffi.INT,save_err=SAVE_ERR,compilation_info=compilation_info))
send = external('send', [socketfd_type, rffi.CCHARP, size_t, rffi.INT],
ssize_t, save_err=SAVE_ERR)
sendto = external('sendto', [socketfd_type, rffi.VOIDP, size_t, rffi.INT,
sockaddr_ptr, socklen_t], ssize_t,
save_err=SAVE_ERR)
sendmsg = jit.dont_look_inside(rffi.llexternal("sendmsg_implementation",
[rffi.INT, sockaddr_ptr, socklen_t, rffi.SIGNEDP, rffi.CCHARPP, rffi.INT,
rffi.SIGNEDP, rffi.SIGNEDP, rffi.CCHARPP, rffi.SIGNEDP, rffi.INT, rffi.INT],
rffi.INT, save_err=SAVE_ERR,
compilation_info=compilation_info))
CMSG_SPACE = jit.dont_look_inside(rffi.llexternal("CMSG_SPACE_wrapper",[size_t], size_t, save_err=SAVE_ERR,compilation_info=compilation_info))
CMSG_LEN = jit.dont_look_inside(rffi.llexternal("CMSG_LEN_wrapper",[size_t], size_t, save_err=SAVE_ERR,compilation_info=compilation_info))
socketshutdown = external('shutdown', [socketfd_type, rffi.INT], rffi.INT,
save_err=SAVE_ERR)
gethostname = external('gethostname', [rffi.CCHARP, rffi.INT], rffi.INT,
save_err=SAVE_ERR)
gethostbyname = external('gethostbyname', [rffi.CCHARP],
lltype.Ptr(cConfig.hostent))
gethostbyaddr = external('gethostbyaddr', [rffi.VOIDP, rffi.INT, rffi.INT], lltype.Ptr(cConfig.hostent))
getservbyname = external('getservbyname', [rffi.CCHARP, rffi.CCHARP], lltype.Ptr(cConfig.servent))
getservbyport = external('getservbyport', [rffi.INT, rffi.CCHARP], lltype.Ptr(cConfig.servent))
getprotobyname = external('getprotobyname', [rffi.CCHARP], lltype.Ptr(cConfig.protoent))
if _POSIX:
fcntl = external('fcntl', [socketfd_type, rffi.INT, rffi.INT], rffi.INT,
save_err=SAVE_ERR, natural_arity=2)
socketpair_t = rffi.CArray(socketfd_type)
socketpair = external('socketpair', [rffi.INT, rffi.INT, rffi.INT,
lltype.Ptr(socketpair_t)], rffi.INT,
save_err=SAVE_ERR)
sethostname = external('sethostname', [rffi.CCHARP, rffi.INT], rffi.INT,
save_err=SAVE_ERR)
if _HAS_AF_PACKET:
ioctl = external('ioctl', [socketfd_type, rffi.INT, lltype.Ptr(ifreq)],
rffi.INT)
if _WIN32:
ioctlsocket = external('ioctlsocket',
[socketfd_type, rffi.LONG, rffi.ULONGP],
rffi.INT, save_err=SAVE_ERR)
select = external('select',
[rffi.INT, fd_set, fd_set,
fd_set, lltype.Ptr(timeval)],
rffi.INT,
save_err=SAVE_ERR)
if_nameindex = rffi.llexternal('if_nameindex', [], lltype.Ptr(if_nameindex_s),
save_err=SAVE_ERR, compilation_info=compilation_info,
calling_conv=calling_conv)
if_freenameindex = rffi.llexternal('if_freenameindex', [lltype.Ptr(if_nameindex_s)],
lltype.Void, save_err=SAVE_ERR, compilation_info=compilation_info,
calling_conv=calling_conv)
FD_CLR = external_c('FD_CLR', [rffi.INT, fd_set], lltype.Void, macro=True)
FD_ISSET = external_c('FD_ISSET', [rffi.INT, fd_set], rffi.INT, macro=True)
FD_SET = external_c('FD_SET', [rffi.INT, fd_set], lltype.Void, macro=True)
FD_ZERO = external_c('FD_ZERO', [fd_set], lltype.Void, macro=True)
if _POSIX:
pollfdarray = rffi.CArray(pollfd)
poll = external('poll', [lltype.Ptr(pollfdarray), nfds_t, rffi.INT],
rffi.INT, save_err=SAVE_ERR)
# workaround for Mac OS/X on which poll() seems to behave a bit strangely
# (see test_recv_send_timeout in pypy.module._socket.test.test_sock_app)
# https://issues.apache.org/bugzilla/show_bug.cgi?id=34332
poll_may_be_broken = _MACOSX
elif WIN32:
from rpython.rlib import rwin32
#
# The following is for rpython.rlib.rpoll
#
WSAEVENT_ARRAY = rffi.CArray(WSAEVENT)
WSACreateEvent = external('WSACreateEvent', [], WSAEVENT)
WSACloseEvent = external('WSACloseEvent', [WSAEVENT], rffi.INT)
WSAEventSelect = external('WSAEventSelect',
[socketfd_type, WSAEVENT, rffi.LONG],
rffi.INT)
WSAWaitForMultipleEvents = external('WSAWaitForMultipleEvents',
[rffi.LONG, lltype.Ptr(WSAEVENT_ARRAY),
rffi.INT, rffi.LONG, rffi.INT],
rffi.ULONG)
WSAEnumNetworkEvents = external('WSAEnumNetworkEvents',
[socketfd_type, WSAEVENT,
lltype.Ptr(WSANETWORKEVENTS)],
rffi.INT)
WSAIoctl = external('WSAIoctl',
[socketfd_type, rwin32.DWORD,
rffi.VOIDP, rwin32.DWORD,
rffi.VOIDP, rwin32.DWORD,
rwin32.LPDWORD, rffi.VOIDP, rffi.VOIDP],
rffi.INT, save_err=SAVE_ERR)
WSAPROTOCOL_INFOW = cConfig.WSAPROTOCOL_INFOW
WSADuplicateSocketW = external('WSADuplicateSocketW',
[socketfd_type, rwin32.DWORD,
lltype.Ptr(WSAPROTOCOL_INFOW)],
rffi.INT, save_err=SAVE_ERR)
WSASocketW = external('WSASocketW',
[rffi.INT, rffi.INT, rffi.INT,
lltype.Ptr(WSAPROTOCOL_INFOW),
rwin32.DWORD, rwin32.DWORD],
socketfd_type, save_err=SAVE_ERR)
tcp_keepalive = cConfig.tcp_keepalive
WSAPROTOCOL_INFO = cConfig.WSAPROTOCOL_INFO
FROM_PROTOCOL_INFO = cConfig.FROM_PROTOCOL_INFO
WSADuplicateSocket = external('WSADuplicateSocketA',
[socketfd_type, rwin32.DWORD,
lltype.Ptr(WSAPROTOCOL_INFO)],
rffi.INT, save_err=SAVE_ERR)
WSASocket = external('WSASocketA',
[rffi.INT, rffi.INT, rffi.INT,
lltype.Ptr(WSAPROTOCOL_INFO),
rwin32.DWORD, rwin32.DWORD],
socketfd_type, save_err=SAVE_ERR)
if WIN32:
WSAData = cConfig.WSAData
WSAStartup = external('WSAStartup', [rwin32.WORD, lltype.Ptr(WSAData)],
rffi.INT)
_WSAGetLastError = external('WSAGetLastError', [], rwin32.DWORD,
_nowrapper=True, sandboxsafe=True)
geterrno = rwin32.GetLastError_saved
# In tests, the first call to GetLastError is always wrong, because error
# is hidden by operations in ll2ctypes. Call it now.
> _WSAGetLastError()
..\rpython\rlib\_rsocket_rffi.py:1582:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <* fn WSAGetLastError>, args = ()
rffi = <module 'rpython.rtyper.lltypesystem.rffi' from 'd:\\pypy_stuff\\buildbot64\\slave\\own-win-x86-64\\build\\rpython\\rtyper\\lltypesystem\\rffi.pyc'>
def __call__(self, *args):
from rpython.rtyper.lltypesystem import rffi
if isinstance(self._T, FuncType):
if len(args) != len(self._T.ARGS):
raise TypeError("calling %r with wrong argument number: %r" %
(self._T, args))
for i, a, ARG in zip(range(len(self._T.ARGS)), args, self._T.ARGS):
if typeOf(a) != ARG:
# ARG could be Void
if ARG == Void:
try:
value = getattr(self._obj, '_void' + str(i))
except AttributeError:
pass
else:
assert a == value
# None is acceptable for any pointer
elif isinstance(ARG, Ptr) and a is None:
pass
# Any pointer is convertible to void*
elif ARG is rffi.VOIDP and isinstance(typeOf(a), Ptr):
pass
# special case: ARG can be a container type, in which
# case a should be a pointer to it. This must also be
# special-cased in the backends.
elif (isinstance(ARG, ContainerType) and
typeOf(a) == Ptr(ARG)):
pass
else:
args_repr = [typeOf(arg) for arg in args]
raise TypeError("calling %r with wrong argument "
"types: %r" % (self._T, args_repr))
callb = self._obj._callable
if callb is None:
raise RuntimeError("calling undefined function")
> return callb(*args)
..\rpython\rtyper\lltypesystem\lltype.py:1384:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <rpython.rtyper.lltypesystem.ll2ctypes.LL2CtypesCallable object at 0x0000010aa94509c0>
argvalues = ()
def __call__(self, *argvalues):
with rlock:
if self.trampoline is None:
# lazily build the corresponding ctypes function object
cfunc = get_ctypes_callable(self.funcptr, self.calling_conv,
> self.natural_arity)
..\rpython\rtyper\lltypesystem\ll2ctypes.py:1339:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
funcptr = <* fn WSAGetLastError>, calling_conv = 'win', natural_arity = -1
def get_ctypes_callable(funcptr, calling_conv, natural_arity):
if not ctypes:
raise ImportError("ctypes is needed to use ll2ctypes")
def get_on_lib(lib, elem):
""" Wrapper to always use lib[func] instead of lib.func
"""
try:
return lib[elem]
except AttributeError:
pass
old_eci = funcptr._obj.compilation_info
funcname = funcptr._obj._name
if hasattr(old_eci, '_with_ctypes'):
old_eci = old_eci._with_ctypes
try:
eci = _eci_cache[old_eci]
except KeyError:
eci = old_eci.compile_shared_lib(ignore_a_files=True,
defines=['RPYTHON_LL2CTYPES'],
> symbolic=True)
..\rpython\rtyper\lltypesystem\ll2ctypes.py:1236:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <ExternalCompilationInfo (pre_include_bits=(), includes=(), include_dirs=(), p...estonly_libraries=(), use_cpp_linker=False, platform=<MsvcPlatform cc=cl.exe>)>
outputfilename = 'd:\\systemtemp\\pytest\\usession-py3.11-415\\shared_cache\\externmod_0'
ignore_a_files = False, debug_mode = True, defines = ['RPYTHON_LL2CTYPES']
symbolic = True
def compile_shared_lib(self, outputfilename=None, ignore_a_files=False,
debug_mode=True, defines=[], symbolic=False):
self = self.convert_sources_to_files()
if ignore_a_files:
if not [fn for fn in self.link_files if fn.endswith('.a')]:
ignore_a_files = False # there are none
if not self.separate_module_files and not ignore_a_files:
return self # xxx there was some condition about win32 here
else:
#basepath = py.path.local(self.separate_module_files[0]).dirpath()
basepath = udir.join('shared_cache')
if outputfilename is None:
# find more or less unique name there
pth = basepath.join('externmod').new(ext=host.so_ext)
num = 0
while pth.check():
pth = basepath.join(
'externmod_%d' % (num,)).new(ext=host.so_ext)
num += 1
basepath.ensure(dir=1)
outputfilename = str(pth.dirpath().join(pth.purebasename))
d = self._copy_attributes()
if ignore_a_files:
d['link_files'] = [fn for fn in d['link_files']
if not fn.endswith('.a')]
if debug_mode and sys.platform != 'win32':
d['compile_extra'] = d['compile_extra'] + ('-g', '-O0')
d['compile_extra'] = d['compile_extra'] + (
'-DRPY_EXTERN=RPY_EXPORTED',)
for define in defines:
d['compile_extra'] += ('-D%s' % define,)
# On ELF platforms (Linux), prevent symbol interposition: when the host
# interpreter (e.g. pypy2.7) also exports symbols like pypysig_counter,
# the shared lib's own references would otherwise resolve to the host's
# copy via the GOT. -Bsymbolic makes the shared lib bind its own global
# symbol references to its own definitions. Only needed when running
# under a host interpreter (tests), not during translation.
if symbolic and sys.platform not in ('win32', 'darwin'):
d['link_extra'] = d['link_extra'] + ('-Wl,-Bsymbolic',)
self = ExternalCompilationInfo(**d)
lib = str(host.compile([], self, outputfilename=outputfilename,
> standalone=False))
..\rpython\translator\tool\cbuild.py:345:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <MsvcPlatform cc=cl.exe>, cfiles = []
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=(), include_dirs=(), p...estonly_libraries=(), use_cpp_linker=False, platform=<MsvcPlatform cc=cl.exe>)>
outputfilename = 'd:\\systemtemp\\pytest\\usession-py3.11-415\\shared_cache\\externmod_0'
standalone = False
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
..\rpython\translator\platform\__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <MsvcPlatform cc=cl.exe>
cfiles = [local('d:\\systemtemp\\pytest\\usession-py3.11-415\\module_cache\\module_0.c'), local('d:\\systemtemp\\pytest\\usessi...py3.11-415\\module_cache\\module_2.c'), local('d:\\systemtemp\\pytest\\usession-py3.11-415\\module_cache\\module_3.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=(), include_dirs=(), p...estonly_libraries=(), use_cpp_linker=False, platform=<MsvcPlatform cc=cl.exe>)>
standalone = False
def _compile_o_files(self, cfiles, eci, standalone=True):
cfiles = self._all_cfiles(cfiles, eci)
compile_args = self._compile_args_from_eci(eci, standalone)
ofiles = []
for cfile in cfiles:
# Windows hack: use masm for files ending in .asm
if str(cfile).lower().endswith('.asm'):
ofiles.append(self._compile_c_file(self.masm, cfile, []))
else:
> ofiles.append(self._compile_c_file(self.cc, cfile, compile_args))
..\rpython\translator\platform\__init__.py:79:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <MsvcPlatform cc=cl.exe>, cc = 'cl.exe'
cfile = local('d:\\systemtemp\\pytest\\usession-py3.11-415\\module_cache\\module_1.c')
compile_args = ['/MD', '/O2', '-DRPY_EXTERN=RPY_EXPORTED', '-DRPYTHON_LL2CTYPES', '/Fdd:\\systemtemp\\pytest\\usession-py3.11-415\\module_cache\\']
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='obj')
# notabene: (tismer)
# This function may be called for .c but also .asm files.
# The c compiler accepts any order of arguments, while
# the assembler still has the old behavior that all options
# must come first, and after the file name all options are ignored.
# So please be careful with the order of parameters! ;-)
pdb_dir = oname.dirname
if pdb_dir:
compile_args = compile_args + ['/Fd%s\\' % (pdb_dir,)]
args = ['/nologo', '/c'] + compile_args + ['/Fo%s' % (oname,), str(cfile)]
> self._execute_c_compiler(cc, args, oname)
..\rpython\translator\platform\windows.py:290:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <MsvcPlatform cc=cl.exe>, cc = 'cl.exe'
args = ['/nologo', '/c', '/MD', '/O2', '-DRPY_EXTERN=RPY_EXPORTED', '-DRPYTHON_LL2CTYPES', ...]
outname = local('d:\\systemtemp\\pytest\\usession-py3.11-415\\module_cache\\module_1.obj')
cwd = None
def _execute_c_compiler(self, cc, args, outname, cwd=None):
#log.execute(cc + ' ' + ' '.join(args))
# 'cc' can also contain some options for the C compiler;
# e.g. it can be "gcc -m32". We handle it by splitting on ' '.
cclist = cc.split()
cc = cclist[0]
args = cclist[1:] + args
returncode, stdout, stderr = _run_subprocess(cc, args, self.c_environ,
cwd)
> self._handle_error(returncode, stdout, stderr, outname)
..\rpython\translator\platform\__init__.py:143:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <MsvcPlatform cc=cl.exe>, returncode = 3221225477, stdout = ''
stderr = ''
outname = local('d:\\systemtemp\\pytest\\usession-py3.11-415\\module_cache\\module_1.obj')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
# Microsoft compilers write compilation errors to stdout
stderr = stdout + stderr
errorfile = outname.new(ext='errors')
errorfile.write(stderr, mode='wb')
if self.log_errors:
stderrlines = stderr.splitlines()
for line in stderrlines:
log.Error(line)
# ^^^ don't use ERROR, because it might actually be fine.
# Also, ERROR confuses lib-python/conftest.py.
> raise CompilationError(stdout, stderr)
E CompilationError: CompilationError(out="""
E """)
..\rpython\translator\platform\windows.py:319: CompilationError
builder: own-win-x86-64 build #2314+
test: pypy/module/test_lib_pypy/test_code_module.py::AppTestCodeModule::()::test_cause_tb