virt_test/bin/python testrunner/runner.py --logfile=testrun.log --config=pypy/testrunner_cfg.py '--config=~/machine_cfg.py' --root=pypy --timeout=4000
in dir /build_dir/own-linux-aarch64/build (timeout 4000 secs)
watching logfiles {'pytestLog': 'testrun.log'}
argv: ['virt_test/bin/python', 'testrunner/runner.py', '--logfile=testrun.log', '--config=pypy/testrunner_cfg.py', '--config=~/machine_cfg.py', '--root=pypy', '--timeout=4000']
environment:
AUDITWHEEL_ARCH=aarch64
AUDITWHEEL_PLAT=manylinux2014_aarch64
AUDITWHEEL_POLICY=manylinux2014
DEVTOOLSET_ROOTPATH=/opt/rh/devtoolset-10/root
HOME=/home/buildslave
HOSTNAME=530e0d063b5c
LANG=en_US.UTF-8
LANGUAGE=en_US.UTF-8
LC_ALL=en_US.UTF-8
LD_LIBRARY_PATH=/usr/local/lib:/opt/rh/devtoolset-10/root/usr/lib64:/opt/rh/devtoolset-10/root/usr/lib:/opt/rh/devtoolset-10/root/usr/lib64/dyninst:/opt/rh/devtoolset-10/root/usr/lib/dyninst:/usr/local/lib64
LOGNAME=buildslave
PATH=/python27_virt/bin:/opt/rh/devtoolset-10/root/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig:/usr/local/lib/pkgconfig
PWD=/build_dir/own-linux-aarch64/build
PYPYCHERRYPICK=
PYPY_GC_NURSERY=16M
PYPY_LOCALBASE=/usr/local
PYPY_MAKE_PORTABLE=1
PYTHONPATH=.:
SHELL=/bin/bash
SHLVL=2
SSL_CERT_FILE=/opt/_internal/certs.pem
TERM=xterm
TMPDIR=/tmp/pytest
USER=buildslave
_=/python27_virt/bin/buildslave
using PTY: False
using config pypy/testrunner_cfg.py
using config /home/buildslave/machine_cfg.py
running 4 parallel test workers
setting MAKEFLAGS to ' ' (space)
-- config/test
-- interpreter/astcompiler/test
-- interpreter/pyparser/test
-- interpreter/test
-- module/__builtin__/test
-- module/__pypy__/test
-- module/_abc/test
-- module/_ast/test
-- module/_cffi_backend/test
-- module/_codecs/test
-- module/_collections/test
-- module/_continuation/test
-- module/_cppyy/test
-- module/_csv/test
-- module/_demo/test
-- module/_hpy_universal/test/_vendored
-- module/_hpy_universal/test/pypy
-- module/_io/test
-- module/_jitlog/test
-- module/_locale/test
-- module/_lsprof/test
-- module/_md5/test
-- module/_minimal_curses/test
-- module/_multibytecodec/test
-- module/_multiprocessing/test
-- module/_opcode/test
-- module/_pickle/test
-- module/_pickle_support/test
-- module/_posixsubprocess/test
-- module/_pypyjson/test
-- module/_random/test
-- module/_rawffi/alt/test
-- module/_rawffi/test
-- module/_socket/test
-- module/_sre/test
-- module/_vmprof/test
-- module/_warnings/test
-- module/_weakref/test
-- module/_winreg/test
-- module/array/test
-- module/atexit/test
-- module/binascii/test
-- module/bz2/test
-- module/cmath/test
-- module/cpyext/test/test_api.py
-- module/cpyext/test/test_arraymodule.py
-- module/cpyext/test/test_async_iter.py
-- module/cpyext/test/test_boolobject.py
-- module/cpyext/test/test_borrow.py
-- module/cpyext/test/test_buffer.py
-- module/cpyext/test/test_bytearrayobject.py
-- module/cpyext/test/test_bytesobject.py
-- module/cpyext/test/test_capsule.py
-- module/cpyext/test/test_cell.py
-- module/cpyext/test/test_classobject.py
-- module/cpyext/test/test_codecs.py
-- module/cpyext/test/test_complexobject.py
-- module/cpyext/test/test_contextvars.py
-- module/cpyext/test/test_cpyext.py
-- module/cpyext/test/test_datetime.py
-- module/cpyext/test/test_dictobject.py
-- module/cpyext/test/test_eval.py
-- module/cpyext/test/test_exception.py
-- module/cpyext/test/test_fileobject.py
-- module/cpyext/test/test_floatobject.py
-- module/cpyext/test/test_frameobject.py
-- module/cpyext/test/test_funcobject.py
-- module/cpyext/test/test_genobject.py
-- module/cpyext/test/test_getargs.py
-- module/cpyext/test/test_import.py
-- module/cpyext/test/test_iterator.py
-- module/cpyext/test/test_listobject.py
-- module/cpyext/test/test_longobject.py
-- module/cpyext/test/test_mapping.py
-- module/cpyext/test/test_marshal.py
-- module/cpyext/test/test_memoryobject.py
-- module/cpyext/test/test_methodobject.py
-- module/cpyext/test/test_misc.py
-- module/cpyext/test/test_module.py
-- module/cpyext/test/test_namespaceobject.py
-- module/cpyext/test/test_ndarrayobject.py
-- module/cpyext/test/test_number.py
-- module/cpyext/test/test_object.py
-- module/cpyext/test/test_pyerrors.py
-- module/cpyext/test/test_pyfile.py
-- module/cpyext/test/test_pymem.py
-- module/cpyext/test/test_pysignals.py
-- module/cpyext/test/test_pystate.py
-- module/cpyext/test/test_pystrhex.py
-- module/cpyext/test/test_pystrtod.py
-- module/cpyext/test/test_sequence.py
-- module/cpyext/test/test_setobject.py
-- module/cpyext/test/test_sliceobject.py
-- module/cpyext/test/test_structseq.py
-- module/cpyext/test/test_sysmodule.py
-- module/cpyext/test/test_thread.py
-- module/cpyext/test/test_traceback.py
-- module/cpyext/test/test_translate.py
-- module/cpyext/test/test_tupleobject.py
-- module/cpyext/test/test_typeobject.py
-- module/cpyext/test/test_unicodeobject.py
-- module/cpyext/test/test_userslots.py
-- module/cpyext/test/test_version.py
-- module/cpyext/test/test_weakref.py
-- module/crypt/test
-- module/errno/test
-- module/exceptions/test
-- module/faulthandler/test
-- module/fcntl/test
-- module/gc/test
-- module/imp/test
-- module/itertools/test
-- module/marshal/test
-- module/math/test
-- module/micronumpy/test
-- module/mmap/test
-- module/operator/test
-- module/posix/test
-- module/pwd/test
-- module/pyexpat/test
-- module/pypyjit/test
-- module/select/test
-- module/signal/test
-- module/struct/test
-- module/sys/test
-- module/termios/test
-- module/test_lib_pypy
-- module/thread/test
-- module/time/test
-- module/token/test
-- module/unicodedata/test
-- module/zipimport/test
-- module/zlib/test
-- objspace/fake/test
-- objspace/std/test
-- objspace/test
-- sandbox/test
-- tool/bench/test
-- tool/memusage/test
-- tool/pytest/fake_pytest/test
-- tool/pytest/test
-- tool/release/test
-- tool/test
-- total: 143 to run
++ 00:28:03 starting config/test [1 started in total]
++ 00:28:03 starting interpreter/astcompiler/test [2 started in total]
++ 00:28:03 starting interpreter/pyparser/test [3 started in total]
++ 00:28:03 starting interpreter/test [4 started in total]
__ config/test [1 done in total, somefailed=False] ____________________________
============================= test session starts ==============================
platform linux2 -- Python 2.7.18, pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/build_dir/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /build_dir/own-linux-aarch64/build/pytest.pyc
rootdir: /build_dir/own-linux-aarch64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 161 items / 1 skipped
config/test/test_pypyoption.py .................................................................................................................................................................
==================== 161 passed, 1 skipped in 8.03 seconds =====================
++ 00:28:13 starting module/__builtin__/test [5 started in total]
__ module/__builtin__/test [2 done in total, somefailed=True] _________________
============================= test session starts ==============================
platform linux2 -- Python 2.7.18, pytest-2.9.2, py-1.4.29, pluggy-0.3.1
hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/build_dir/own-linux-aarch64/build/pypy/.hypothesis/examples')
pytest-2.9.2 from /build_dir/own-linux-aarch64/build/pytest.pyc
rootdir: /build_dir/own-linux-aarch64/build, inifile: pytest.ini
plugins: hypothesis-4.39.3
collected 287 items / 4 errors
module/__builtin__/test/test_abstractinst.py EEEEEEEEEEEEE
module/__builtin__/test/test_breakpoint.py EEEEEEEE
module/__builtin__/test/test_builtin.py EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
module/__builtin__/test/test_compile.py EE
module/__builtin__/test/test_construct_singletons.py E
module/__builtin__/test/test_descriptor.py EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
module/__builtin__/test/test_dir.py EEEEEEEEEEE
module/__builtin__/test/test_filter.py EEEEEEEE
module/__builtin__/test/test_filter_pickle.py EEEEE
module/__builtin__/test/test_format.py E
module/__builtin__/test/test_functional.py EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
module/__builtin__/test/test_map_pickle.py EEE
module/__builtin__/test/test_minmax.py EEEEEEEEEEEEEEEEEEEEEEE
module/__builtin__/test/test_rawinput.py EE
module/__builtin__/test/test_sum.py E
module/__builtin__/test/test_vars.py EEE
module/__builtin__/test/test_zip.py EEEEEEEEEEE
module/__builtin__/test/test_zip_pickle.py E
==================================== ERRORS ====================================
_______ ERROR collecting pypy/module/__builtin__/test/apptest_compile.py _______
tool/pytest/apptest2.py:25: in collect
space = objspace.gettestobjspace(**spaceconfig)
tool/pytest/objspace.py:24: in gettestobjspace
space = maketestobjspace(config)
tool/pytest/objspace.py:34: in maketestobjspace
space = make_objspace(config)
tool/option.py:33: in make_objspace
return StdObjSpace(config)
interpreter/baseobjspace.py:455: in __init__
self.initialize()
objspace/std/objspace.py:115: in initialize
self.make_builtins()
interpreter/baseobjspace.py:634: in make_builtins
mod = Module(self, w_name)
module/imp/moduledef.py:44: in __init__
from pypy.module.imp import interp_imp
module/imp/interp_imp.py:1: in <module>
from pypy.module.imp import importing
module/imp/importing.py:14: in <module>
from rpython.rlib import streamio, jit
../rpython/rlib/streamio.py:40: in <module>
from rpython.rlib import rposix, nonconst, _rsocket_rffi as _c
../rpython/rlib/_rsocket_rffi.py:1222: in <module>
cConfig.__dict__.update(platform.configure(CConfig))
../rpython/rtyper/tool/rffi_platform.py:216: in configure
for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:241: in configure_entries
writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:745: in run_example_code
output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/tool/gcc_cache.py:28: in build_executable_cache
result = platform.execute(platform.compile(c_files, eci))
../rpython/translator/platform/__init__.py:57: in compile
ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:79: in _compile_o_files
ofiles.append(self._compile_c_file(self.cc, cfile, compile_args))
../rpython/translator/platform/posix.py:44: in _compile_c_file
cwd=str(cfile.dirpath()))
../rpython/translator/platform/__init__.py:143: in _execute_c_compiler
self._handle_error(returncode, stdout, stderr, outname)
../rpython/translator/platform/__init__.py:155: in _handle_error
raise CompilationError(stdout, stderr)
E CompilationError: CompilationError(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_83.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_83.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_83.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_83.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_83.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_83.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_83.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_83.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
------------------------------- Captured stderr --------------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_83.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_83.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_83.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_83.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_83.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_83.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_83.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_83.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
_____ ERROR collecting pypy/module/__builtin__/test/apptest_descriptor.py ______
tool/pytest/apptest2.py:25: in collect
space = objspace.gettestobjspace(**spaceconfig)
tool/pytest/objspace.py:24: in gettestobjspace
space = maketestobjspace(config)
tool/pytest/objspace.py:34: in maketestobjspace
space = make_objspace(config)
tool/option.py:33: in make_objspace
return StdObjSpace(config)
interpreter/baseobjspace.py:455: in __init__
self.initialize()
objspace/std/objspace.py:115: in initialize
self.make_builtins()
interpreter/baseobjspace.py:634: in make_builtins
mod = Module(self, w_name)
module/imp/moduledef.py:44: in __init__
from pypy.module.imp import interp_imp
module/imp/interp_imp.py:1: in <module>
from pypy.module.imp import importing
module/imp/importing.py:14: in <module>
from rpython.rlib import streamio, jit
../rpython/rlib/streamio.py:40: in <module>
from rpython.rlib import rposix, nonconst, _rsocket_rffi as _c
../rpython/rlib/_rsocket_rffi.py:1222: in <module>
cConfig.__dict__.update(platform.configure(CConfig))
../rpython/rtyper/tool/rffi_platform.py:216: in configure
for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:241: in configure_entries
writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:745: in run_example_code
output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/tool/gcc_cache.py:28: in build_executable_cache
result = platform.execute(platform.compile(c_files, eci))
../rpython/translator/platform/__init__.py:57: in compile
ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:79: in _compile_o_files
ofiles.append(self._compile_c_file(self.cc, cfile, compile_args))
../rpython/translator/platform/posix.py:44: in _compile_c_file
cwd=str(cfile.dirpath()))
../rpython/translator/platform/__init__.py:143: in _execute_c_compiler
self._handle_error(returncode, stdout, stderr, outname)
../rpython/translator/platform/__init__.py:155: in _handle_error
raise CompilationError(stdout, stderr)
E CompilationError: CompilationError(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_84.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_84.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_84.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_84.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_84.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_84.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_84.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_84.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
------------------------------- Captured stderr --------------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_84.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_84.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_84.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_84.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_84.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_84.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_84.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_84.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
______ ERROR collecting pypy/module/__builtin__/test/apptest_operator.py _______
tool/pytest/apptest2.py:25: in collect
space = objspace.gettestobjspace(**spaceconfig)
tool/pytest/objspace.py:24: in gettestobjspace
space = maketestobjspace(config)
tool/pytest/objspace.py:34: in maketestobjspace
space = make_objspace(config)
tool/option.py:33: in make_objspace
return StdObjSpace(config)
interpreter/baseobjspace.py:455: in __init__
self.initialize()
objspace/std/objspace.py:115: in initialize
self.make_builtins()
interpreter/baseobjspace.py:634: in make_builtins
mod = Module(self, w_name)
module/imp/moduledef.py:44: in __init__
from pypy.module.imp import interp_imp
module/imp/interp_imp.py:1: in <module>
from pypy.module.imp import importing
module/imp/importing.py:14: in <module>
from rpython.rlib import streamio, jit
../rpython/rlib/streamio.py:40: in <module>
from rpython.rlib import rposix, nonconst, _rsocket_rffi as _c
../rpython/rlib/_rsocket_rffi.py:1222: in <module>
cConfig.__dict__.update(platform.configure(CConfig))
../rpython/rtyper/tool/rffi_platform.py:216: in configure
for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:241: in configure_entries
writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:745: in run_example_code
output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/tool/gcc_cache.py:28: in build_executable_cache
result = platform.execute(platform.compile(c_files, eci))
../rpython/translator/platform/__init__.py:57: in compile
ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:79: in _compile_o_files
ofiles.append(self._compile_c_file(self.cc, cfile, compile_args))
../rpython/translator/platform/posix.py:44: in _compile_c_file
cwd=str(cfile.dirpath()))
../rpython/translator/platform/__init__.py:143: in _execute_c_compiler
self._handle_error(returncode, stdout, stderr, outname)
../rpython/translator/platform/__init__.py:155: in _handle_error
raise CompilationError(stdout, stderr)
E CompilationError: CompilationError(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_85.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_85.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_85.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_85.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_85.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_85.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_85.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_85.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
------------------------------- Captured stderr --------------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_85.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_85.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_85.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_85.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_85.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_85.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_85.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_85.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
________ ERROR collecting pypy/module/__builtin__/test/apptest_print.py ________
tool/pytest/apptest2.py:25: in collect
space = objspace.gettestobjspace(**spaceconfig)
tool/pytest/objspace.py:24: in gettestobjspace
space = maketestobjspace(config)
tool/pytest/objspace.py:34: in maketestobjspace
space = make_objspace(config)
tool/option.py:33: in make_objspace
return StdObjSpace(config)
interpreter/baseobjspace.py:455: in __init__
self.initialize()
objspace/std/objspace.py:115: in initialize
self.make_builtins()
interpreter/baseobjspace.py:634: in make_builtins
mod = Module(self, w_name)
module/imp/moduledef.py:44: in __init__
from pypy.module.imp import interp_imp
module/imp/interp_imp.py:1: in <module>
from pypy.module.imp import importing
module/imp/importing.py:14: in <module>
from rpython.rlib import streamio, jit
../rpython/rlib/streamio.py:40: in <module>
from rpython.rlib import rposix, nonconst, _rsocket_rffi as _c
../rpython/rlib/_rsocket_rffi.py:1222: in <module>
cConfig.__dict__.update(platform.configure(CConfig))
../rpython/rtyper/tool/rffi_platform.py:216: in configure
for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:241: in configure_entries
writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:745: in run_example_code
output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/tool/gcc_cache.py:28: in build_executable_cache
result = platform.execute(platform.compile(c_files, eci))
../rpython/translator/platform/__init__.py:57: in compile
ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:79: in _compile_o_files
ofiles.append(self._compile_c_file(self.cc, cfile, compile_args))
../rpython/translator/platform/posix.py:44: in _compile_c_file
cwd=str(cfile.dirpath()))
../rpython/translator/platform/__init__.py:143: in _execute_c_compiler
self._handle_error(returncode, stdout, stderr, outname)
../rpython/translator/platform/__init__.py:155: in _handle_error
raise CompilationError(stdout, stderr)
E CompilationError: CompilationError(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_86.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_86.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_86.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_86.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_86.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_86.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_86.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_86.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
------------------------------- Captured stderr --------------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_86.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_86.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_86.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_86.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_86.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_86.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_86.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_86.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
___________ ERROR at setup of TestAbstractInst.test_abstract_isclass ___________
item = <Function 'test_abstract_isclass'>
@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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tool/pytest/objspace.py:24: in gettestobjspace
space = maketestobjspace(config)
tool/pytest/objspace.py:34: in maketestobjspace
space = make_objspace(config)
tool/option.py:33: in make_objspace
return StdObjSpace(config)
interpreter/baseobjspace.py:455: in __init__
self.initialize()
objspace/std/objspace.py:115: in initialize
self.make_builtins()
interpreter/baseobjspace.py:634: in make_builtins
mod = Module(self, w_name)
module/imp/moduledef.py:44: in __init__
from pypy.module.imp import interp_imp
module/imp/interp_imp.py:1: in <module>
from pypy.module.imp import importing
module/imp/importing.py:14: in <module>
from rpython.rlib import streamio, jit
../rpython/rlib/streamio.py:40: in <module>
from rpython.rlib import rposix, nonconst, _rsocket_rffi as _c
../rpython/rlib/_rsocket_rffi.py:1222: in <module>
cConfig.__dict__.update(platform.configure(CConfig))
../rpython/rtyper/tool/rffi_platform.py:216: in configure
for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:241: in configure_entries
writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:745: in run_example_code
output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/tool/gcc_cache.py:28: in build_executable_cache
result = platform.execute(platform.compile(c_files, eci))
../rpython/translator/platform/__init__.py:57: in compile
ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:79: in _compile_o_files
ofiles.append(self._compile_c_file(self.cc, cfile, compile_args))
../rpython/translator/platform/posix.py:44: in _compile_c_file
cwd=str(cfile.dirpath()))
../rpython/translator/platform/__init__.py:143: in _execute_c_compiler
self._handle_error(returncode, stdout, stderr, outname)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_87.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/us...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_87.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_87.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_87.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_87.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_87.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_87.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_87.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_87.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_87.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_87.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_87.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_87.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_87.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_87.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_87.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_87.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_87.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
__________ ERROR at setup of TestAbstractInst.test_abstract_getclass ___________
item = <Function 'test_abstract_getclass'>
@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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tool/pytest/objspace.py:24: in gettestobjspace
space = maketestobjspace(config)
tool/pytest/objspace.py:34: in maketestobjspace
space = make_objspace(config)
tool/option.py:33: in make_objspace
return StdObjSpace(config)
interpreter/baseobjspace.py:455: in __init__
self.initialize()
objspace/std/objspace.py:115: in initialize
self.make_builtins()
interpreter/baseobjspace.py:634: in make_builtins
mod = Module(self, w_name)
module/imp/moduledef.py:44: in __init__
from pypy.module.imp import interp_imp
module/imp/interp_imp.py:1: in <module>
from pypy.module.imp import importing
module/imp/importing.py:14: in <module>
from rpython.rlib import streamio, jit
../rpython/rlib/streamio.py:40: in <module>
from rpython.rlib import rposix, nonconst, _rsocket_rffi as _c
../rpython/rlib/_rsocket_rffi.py:1222: in <module>
cConfig.__dict__.update(platform.configure(CConfig))
../rpython/rtyper/tool/rffi_platform.py:216: in configure
for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:241: in configure_entries
writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:745: in run_example_code
output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/tool/gcc_cache.py:28: in build_executable_cache
result = platform.execute(platform.compile(c_files, eci))
../rpython/translator/platform/__init__.py:57: in compile
ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:79: in _compile_o_files
ofiles.append(self._compile_c_file(self.cc, cfile, compile_args))
../rpython/translator/platform/posix.py:44: in _compile_c_file
cwd=str(cfile.dirpath()))
../rpython/translator/platform/__init__.py:143: in _execute_c_compiler
self._handle_error(returncode, stdout, stderr, outname)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_88.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/us...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_88.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_88.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_88.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_88.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_88.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_88.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_88.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_88.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_88.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_88.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_88.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_88.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_88.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_88.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_88.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_88.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_88.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
________ ERROR at setup of AppTestAbstractInst.test_abstract_isinstance ________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_89.c: In functio...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdcd27dd0>, 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_abstract_isinstance'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_abstract_isinstance'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_abstract_isinstance'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_abstract_isinstance'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_abstract_isinstance'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_abstract_isinstance'>}
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_abstract_isinstance'>, '__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 0xfffcdcda9550>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...isinstance'>, '__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 0xfffcdcda9460>
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 0xfffcdcda9460>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...isinstance'>, '__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_abstract_isinstance'>, '__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_abstract_isinstance'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdd672e90>
key = (((True, False, False, True, False, 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 0xfffcdd672e90>
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 0xfffcdd672e90>
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 0xfffcdd672e90>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdd68d6d0>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdcc22520>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdcc3d950>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdcc38f10>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdcc49050>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_89.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_89.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_89.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_89.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_89.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_89.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_89.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/us...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_89.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_89.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_89.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_89.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_89.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_89.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_89.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_89.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_89.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_89.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_89.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_89.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_89.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_89.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_89.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_89.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_89.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
________ ERROR at setup of AppTestAbstractInst.test_abstract_issubclass ________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_90.c: In functio...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdce50d50>, 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_abstract_issubclass'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_abstract_issubclass'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_abstract_issubclass'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_abstract_issubclass'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_abstract_issubclass'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_abstract_issubclass'>}
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_abstract_issubclass'>, '__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 0xfffcdce7b640>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...issubclass'>, '__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 0xfffcdce7b6e0>
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 0xfffcdce7b6e0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...issubclass'>, '__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_abstract_issubclass'>, '__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_abstract_issubclass'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdd238d90>
key = (((True, False, False, True, False, 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 0xfffcdd238d90>
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 0xfffcdd238d90>
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 0xfffcdd238d90>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdd659250>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcddbf0e50>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdda004d0>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdda1ca50>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd9e8b90>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_90.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_90.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_90.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_90.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_90.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_90.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_90.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/us...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_90.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_90.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_90.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_90.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_90.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_90.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_90.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_90.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_90.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_90.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_90.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_90.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_90.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_90.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_90.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_90.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_90.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
____________ ERROR at setup of AppTestAbstractInst.test_overriding _____________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_91.c: In functio...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdd5024d0>, 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_overriding'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_overriding'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_overriding'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_overriding'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_overriding'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_overriding'>}
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_overriding'>, '__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 0xfffcddb16910>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...overriding'>, '__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 0xfffcddb16820>
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 0xfffcddb16820>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...overriding'>, '__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_overriding'>, '__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_overriding'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdce22990>
key = (((True, False, False, True, False, 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 0xfffcdce22990>
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 0xfffcdce22990>
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 0xfffcdce22990>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdd48ccd0>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdd663d70>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd680fd0>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdd6805d0>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd67f6d0>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_91.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_91.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_91.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_91.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_91.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_91.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_91.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/us...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_91.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_91.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_91.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_91.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_91.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_91.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_91.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_91.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_91.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_91.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_91.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_91.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_91.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_91.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_91.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_91.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_91.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
_ ERROR at setup of AppTestAbstractInst.test_dont_call_instancecheck_fast_path _
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_92.c: In functio...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdd024ed0>, 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_dont_call_instancecheck_fast_pa...__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_dont_call_instancecheck_fast_path'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_dont_call_instancecheck_fast_pa...__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_dont_call_instancecheck_fast_path'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_dont_call_instancecheck_fast_pa...__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_dont_call_instancecheck_fast_path'>}
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_dont_call_instancecheck_fast_path'>, '__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 0xfffcddb2f6e0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._fast_path'>, '__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 0xfffcddb2f4b0>
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 0xfffcddb2f4b0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._fast_path'>, '__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_dont_call_instancecheck_fast_path'>, '__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_dont_call_instancecheck_fast_path'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdd932650>
key = (((True, False, False, True, False, 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 0xfffcdd932650>
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 0xfffcdd932650>
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 0xfffcdd932650>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcddc9b190>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcddc83d00>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdcd34410>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdcd4c410>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdcd4dad0>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_92.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_92.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_92.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_92.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_92.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_92.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_92.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/us...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_92.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_92.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_92.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_92.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_92.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_92.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_92.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_92.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_92.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_92.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_92.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_92.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_92.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_92.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_92.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_92.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_92.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
_ ERROR at setup of AppTestAbstractInst.test_instancecheck_exception_not_eaten _
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_93.c: In functio...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdd707dd0>, 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_instancecheck_exception_not_eat...__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_instancecheck_exception_not_eaten'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_instancecheck_exception_not_eat...__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_instancecheck_exception_not_eaten'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_instancecheck_exception_not_eat...__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_instancecheck_exception_not_eaten'>}
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_instancecheck_exception_not_eaten'>, '__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 0xfffcdce515f0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._not_eaten'>, '__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 0xfffcdce51cd0>
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 0xfffcdce51cd0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._not_eaten'>, '__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_instancecheck_exception_not_eaten'>, '__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_instancecheck_exception_not_eaten'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdd24a9d0>
key = (((True, False, False, True, False, 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 0xfffcdd24a9d0>
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 0xfffcdd24a9d0>
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 0xfffcdd24a9d0>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdce9ca50>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdd055130>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd039410>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcddbf4a90>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd238610>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_93.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_93.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_93.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_93.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_93.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_93.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_93.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/us...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_93.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_93.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_93.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_93.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_93.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_93.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_93.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_93.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_93.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_93.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_93.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_93.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_93.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_93.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_93.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_93.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_93.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
__ ERROR at setup of AppTestAbstractInst.test_issubclass_exception_not_eaten ___
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_94.c: In functio...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdd22cdd0>, 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_issubclass_exception_not_eaten'...all__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_issubclass_exception_not_eaten'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_issubclass_exception_not_eaten'...all__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_issubclass_exception_not_eaten'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_issubclass_exception_not_eaten'...all__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_issubclass_exception_not_eaten'>}
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_issubclass_exception_not_eaten'>, '__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 0xfffcdcfa4870>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._not_eaten'>, '__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 0xfffcdcfa4140>
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 0xfffcdcfa4140>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._not_eaten'>, '__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_issubclass_exception_not_eaten'>, '__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_issubclass_exception_not_eaten'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdcdcf5d0>
key = (((True, False, False, True, False, 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 0xfffcdcdcf5d0>
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 0xfffcdcdcf5d0>
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 0xfffcdcdcf5d0>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdd514850>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdd9fdc20>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd8d8b50>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdd8d8150>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd8c1250>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_94.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_94.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_94.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_94.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_94.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_94.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_94.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/us...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_94.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_94.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_94.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_94.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_94.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_94.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_94.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_94.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_94.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_94.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_94.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_94.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_94.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_94.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_94.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_94.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_94.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
______ ERROR at setup of AppTestAbstractInst.test_issubclass_no_fallback _______
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_95.c: In functio...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcddcc6dd0>, 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_issubclass_no_fallback'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_issubclass_no_fallback'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_issubclass_no_fallback'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_issubclass_no_fallback'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_issubclass_no_fallback'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_issubclass_no_fallback'>}
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_issubclass_no_fallback'>, '__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 0xfffcdcffc230>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...o_fallback'>, '__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 0xfffcdcffc320>
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 0xfffcdcffc320>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...o_fallback'>, '__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_issubclass_no_fallback'>, '__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_issubclass_no_fallback'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdcafcf90>
key = (((True, False, False, True, False, 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 0xfffcdcafcf90>
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 0xfffcdcafcf90>
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 0xfffcdcafcf90>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdd86ffd0>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcddedefa0>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdcb22090>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdcf278d0>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdcdba4d0>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_95.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_95.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_95.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_95.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_95.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_95.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_95.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/us...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_95.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_95.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_95.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_95.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_95.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_95.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_95.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_95.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_95.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_95.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_95.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_95.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_95.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_95.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_95.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_95.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_95.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
ERROR at setup of AppTestAbstractInst.test_exception_match_does_not_call_subclasscheck
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_96.c: In functio...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcddcc82d0>, 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_exception_match_does_not_call_s...tiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_exception_match_does_not_call_subclasscheck'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_exception_match_does_not_call_s...tiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_exception_match_does_not_call_subclasscheck'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_exception_match_does_not_call_s...tiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_exception_match_does_not_call_subclasscheck'>}
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_exception_match_does_not_call_subclasscheck'>, '__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 0xfffcddafa460>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...classcheck'>, '__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 0xfffcddafa960>
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 0xfffcddafa960>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...classcheck'>, '__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_exception_match_does_not_call_subclasscheck'>, '__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_exception_match_does_not_call_subclasscheck'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdd918150>
key = (((True, False, False, True, False, 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 0xfffcdd918150>
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 0xfffcdd918150>
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 0xfffcdd918150>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdd227710>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdd9fda60>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdda04990>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdd9e1f50>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdda1a090>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_96.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_96.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_96.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_96.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_96.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_96.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_96.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/us...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_96.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_96.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_96.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_96.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_96.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_96.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_96.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_96.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_96.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_96.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_96.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_96.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_96.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_96.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_96.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_96.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_96.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
ERROR at setup of AppTestAbstractInst.test_exception_raising_does_not_call_subclasscheck
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_97.c: In functio...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdcc1bc50>, 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_exception_raising_does_not_call...Call 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_exception_raising_does_not_call_subclasscheck'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_exception_raising_does_not_call...Call 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_exception_raising_does_not_call_subclasscheck'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_exception_raising_does_not_call...Call 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_exception_raising_does_not_call_subclasscheck'>}
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_exception_raising_does_not_call_subclasscheck'>, '__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 0xfffcdd7bf460>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...classcheck'>, '__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 0xfffcdd7bf3c0>
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 0xfffcdd7bf3c0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...classcheck'>, '__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_exception_raising_does_not_call_subclasscheck'>, '__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_exception_raising_does_not_call_subclasscheck'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdcaded90>
key = (((True, False, False, True, False, 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 0xfffcdcaded90>
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 0xfffcdcaded90>
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 0xfffcdcaded90>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcddc84a90>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcddc96440>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd6e4d90>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdd6e4390>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd70c490>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_97.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_97.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_97.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_97.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_97.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_97.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_97.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/us...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_97.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_97.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_97.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_97.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_97.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_97.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_97.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_97.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_97.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_97.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_97.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_97.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_97.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_97.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_97.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_97.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_97.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
____ ERROR at setup of AppTestAbstractInst.test_exception_bad_subclasscheck ____
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_98.c: In functio...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcddc7abd0>, 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_exception_bad_subclasscheck'>, ...ticall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_exception_bad_subclasscheck'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_exception_bad_subclasscheck'>, ...ticall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_exception_bad_subclasscheck'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_exception_bad_subclasscheck'>, ...ticall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_exception_bad_subclasscheck'>}
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_exception_bad_subclasscheck'>, '__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 0xfffcdcc98d20>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...classcheck'>, '__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 0xfffcdcc98c30>
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 0xfffcdcc98c30>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...classcheck'>, '__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_exception_bad_subclasscheck'>, '__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_exception_bad_subclasscheck'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdce9cf50>
key = (((True, False, False, True, False, 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 0xfffcdce9cf50>
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 0xfffcdce9cf50>
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 0xfffcdce9cf50>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdcc97990>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdda1e2f0>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd7c8050>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdce2ea50>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd5192d0>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_98.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_98.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_98.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_98.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_98.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_98.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_98.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/us...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_98.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_98.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_98.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_98.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_98.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_98.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_98.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_98.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_98.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_98.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_98.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_98.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_98.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_98.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_98.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_98.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_98.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
___ ERROR at setup of AppTestAbstractInst.test_exception_contains_type_name ____
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_99.c: In functio...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdd4f5c50>, 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_exception_contains_type_name'>,...icall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_exception_contains_type_name'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_exception_contains_type_name'>,...icall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_exception_contains_type_name'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_exception_contains_type_name'>,...icall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_exception_contains_type_name'>}
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_exception_contains_type_name'>, '__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 0xfffcddc5e780>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._type_name'>, '__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 0xfffcddc5e9b0>
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 0xfffcddc5e9b0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._type_name'>, '__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_exception_contains_type_name'>, '__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_exception_contains_type_name'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdd8e71d0>
key = (((True, False, False, True, False, 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 0xfffcdd8e71d0>
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 0xfffcdd8e71d0>
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 0xfffcdd8e71d0>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdce54850>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdd23f3d0>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd2484d0>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdd224c50>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd24fb90>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_99.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_99.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_99.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_99.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_99.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_99.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_99.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/us...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_99.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_99.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_99.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_99.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_99.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_99.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_99.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_99.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_99.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_99.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_99.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_99.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_99.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_99.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_99.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_99.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_99.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
_______________ ERROR at setup of AppTestBreakpoint.test_default _______________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_100.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcddecc050>, 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_default'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_default'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_default'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_default'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_default'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_default'>}
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_default'>, '__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 0xfffcdda89780>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...st_default'>, '__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 0xfffcdda89050>
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 0xfffcdda89050>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...st_default'>, '__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_default'>, '__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_default'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdd340a90>
key = (((True, False, False, True, False, 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 0xfffcdd340a90>
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 0xfffcdd340a90>
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 0xfffcdd340a90>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdcc97990>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdd4681a0>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdcf07990>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdcd12550>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd039550>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_100.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_100.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_100.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_100.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_100.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_100.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_100.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_100.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_100.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_100.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_100.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_100.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_100.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_100.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_100.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_100.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_100.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_100.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_100.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_100.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_100.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_100.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_100.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_100.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
_____________ ERROR at setup of AppTestBreakpoint.test_args_kwargs _____________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_101.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdd7d1850>, 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_args_kwargs'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_args_kwargs'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_args_kwargs'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_args_kwargs'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_args_kwargs'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_args_kwargs'>}
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_args_kwargs'>, '__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 0xfffcdcb377d0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...rgs_kwargs'>, '__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 0xfffcdcb37b90>
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 0xfffcdcb37b90>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...rgs_kwargs'>, '__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_args_kwargs'>, '__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_args_kwargs'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdd25d110>
key = (((True, False, False, True, False, 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 0xfffcdd25d110>
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 0xfffcdd25d110>
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 0xfffcdd25d110>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdd4ee990>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdcc257c0>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdcca8c50>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdcca8910>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd268450>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_101.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_101.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_101.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_101.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_101.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_101.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_101.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_101.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_101.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_101.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_101.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_101.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_101.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_101.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_101.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_101.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_101.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_101.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_101.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_101.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_101.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_101.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_101.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_101.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
___________ ERROR at setup of AppTestBreakpoint.test_breakpointhook ____________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_102.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdd41fb50>, 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_breakpointhook'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_breakpointhook'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_breakpointhook'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_breakpointhook'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_breakpointhook'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_breakpointhook'>}
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_breakpointhook'>, '__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 0xfffcdcc7c370>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...kpointhook'>, '__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 0xfffcdcc7c0a0>
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 0xfffcdcc7c0a0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...kpointhook'>, '__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_breakpointhook'>, '__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_breakpointhook'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdd3ec790>
key = (((True, False, False, True, False, 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 0xfffcdd3ec790>
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 0xfffcdd3ec790>
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 0xfffcdd3ec790>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdd3ed4d0>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcddc89a60>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcddc84750>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcddc6ad10>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcddc86e10>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_102.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_102.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_102.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_102.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_102.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_102.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_102.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_102.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_102.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_102.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_102.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_102.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_102.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_102.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_102.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_102.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_102.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_102.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_102.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_102.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_102.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_102.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_102.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_102.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
_________ ERROR at setup of AppTestBreakpoint.test_breakpointhook_lost _________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_103.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcddc98b50>, 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_breakpointhook_lost'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_breakpointhook_lost'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_breakpointhook_lost'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_breakpointhook_lost'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_breakpointhook_lost'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_breakpointhook_lost'>}
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_breakpointhook_lost'>, '__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 0xfffcdd4150a0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...thook_lost'>, '__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 0xfffcdd415280>
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 0xfffcdd415280>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...thook_lost'>, '__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_breakpointhook_lost'>, '__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_breakpointhook_lost'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdda02fd0>
key = (((True, False, False, True, False, 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 0xfffcdda02fd0>
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 0xfffcdda02fd0>
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 0xfffcdda02fd0>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdd907510>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdcc28980>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd64be50>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcddd01d50>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd340ad0>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_103.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_103.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_103.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_103.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_103.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_103.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_103.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_103.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_103.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_103.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_103.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_103.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_103.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_103.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_103.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_103.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_103.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_103.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_103.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_103.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_103.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_103.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_103.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_103.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
_____________ ERROR at setup of AppTestBreakpoint.test_env_default _____________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_104.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdd5058d0>, 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_env_default'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_env_default'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_env_default'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_env_default'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_env_default'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_env_default'>}
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_env_default'>, '__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 0xfffcdcf31050>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...nv_default'>, '__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 0xfffcdcf31370>
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 0xfffcdcf31370>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...nv_default'>, '__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_env_default'>, '__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_env_default'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdd146890>
key = (((True, False, False, True, False, 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 0xfffcdd146890>
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 0xfffcdd146890>
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 0xfffcdd146890>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdda01cd0>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdd6e1980>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd777950>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdd777f50>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd2624d0>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_104.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_104.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_104.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_104.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_104.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_104.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_104.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_104.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_104.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_104.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_104.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_104.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_104.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_104.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_104.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_104.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_104.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_104.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_104.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_104.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_104.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_104.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_104.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_104.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
_____________ ERROR at setup of AppTestBreakpoint.test_env_disable _____________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_105.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdd8d41d0>, 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_env_disable'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_env_disable'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_env_disable'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_env_disable'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_env_disable'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_env_disable'>}
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_env_disable'>, '__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 0xfffcdd72a140>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...nv_disable'>, '__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 0xfffcdd72a280>
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 0xfffcdd72a280>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...nv_disable'>, '__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_env_disable'>, '__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_env_disable'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdcb1e690>
key = (((True, False, False, True, False, 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 0xfffcdcb1e690>
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 0xfffcdcb1e690>
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 0xfffcdcb1e690>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdd7b6a90>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdd412ec0>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd05dad0>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcddc8c550>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd3b78d0>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_105.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_105.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_105.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_105.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_105.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_105.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_105.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_105.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_105.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_105.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_105.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_105.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_105.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_105.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_105.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_105.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_105.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_105.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_105.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_105.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_105.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_105.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_105.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_105.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
______________ ERROR at setup of AppTestBreakpoint.test_env_other ______________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_106.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdd05e8d0>, 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_env_other'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_env_other'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_env_other'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_env_other'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_env_other'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_env_other'>}
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_env_other'>, '__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 0xfffcdca05230>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._env_other'>, '__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 0xfffcdcf12370>
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 0xfffcdcf12370>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._env_other'>, '__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_env_other'>, '__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_env_other'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdcd56e10>
key = (((True, False, False, True, False, 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 0xfffcdcd56e10>
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 0xfffcdcd56e10>
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 0xfffcdcd56e10>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcddc90350>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdd8c98a0>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd8b55d0>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdd8bab90>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd8b6c90>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_106.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_106.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_106.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_106.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_106.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_106.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_106.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_106.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_106.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_106.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_106.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_106.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_106.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_106.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_106.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_106.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_106.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_106.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_106.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_106.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_106.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_106.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_106.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_106.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
___________ ERROR at setup of AppTestBreakpoint.test_env_nonexistent ___________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_107.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcddb968d0>, 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_env_nonexistent'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_env_nonexistent'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_env_nonexistent'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_env_nonexistent'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_env_nonexistent'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_env_nonexistent'>}
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_env_nonexistent'>, '__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 0xfffcdd875af0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...onexistent'>, '__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 0xfffcdd875cd0>
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 0xfffcdd875cd0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...onexistent'>, '__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_env_nonexistent'>, '__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_env_nonexistent'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdd887a90>
key = (((True, False, False, True, False, 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 0xfffcdd887a90>
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 0xfffcdd887a90>
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 0xfffcdd887a90>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdd3ec750>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdd4f3d00>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdcfbbb90>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdcfbb190>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdcb1ef10>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_107.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_107.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_107.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_107.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_107.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_107.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_107.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_107.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_107.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_107.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_107.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_107.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_107.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_107.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_107.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_107.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_107.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_107.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_107.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_107.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_107.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_107.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_107.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_107.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
____________ ERROR at setup of AppTestBuiltinApp.test_builtin_names ____________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_108.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdd0dea50>, 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_builtin_names'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_builtin_names'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_builtin_names'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_builtin_names'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_builtin_names'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_builtin_names'>}
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_builtin_names'>, '__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 0xfffcddb94b40>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ltin_names'>, '__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 0xfffcddb94730>
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 0xfffcddb94730>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ltin_names'>, '__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_builtin_names'>, '__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_builtin_names'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdda01650>
key = (((True, False, False, True, False, 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 0xfffcdda01650>
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 0xfffcdda01650>
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 0xfffcdda01650>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdcc02d50>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdd8ba440>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd404510>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdd8d8c10>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdcfd3210>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_108.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_108.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_108.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_108.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_108.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_108.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_108.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_108.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_108.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_108.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_108.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_108.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_108.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_108.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_108.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_108.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_108.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_108.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_108.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_108.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_108.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_108.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_108.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_108.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
_____________ ERROR at setup of AppTestBuiltinApp.test_bytes_alias _____________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_109.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcddc9e8d0>, 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_bytes_alias'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_bytes_alias'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_bytes_alias'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_bytes_alias'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_bytes_alias'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_bytes_alias'>}
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_bytes_alias'>, '__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 0xfffcdd04d460>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ytes_alias'>, '__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 0xfffcdd04d8c0>
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 0xfffcdd04d8c0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ytes_alias'>, '__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_bytes_alias'>, '__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_bytes_alias'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdd5eba50>
key = (((True, False, False, True, False, 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 0xfffcdd5eba50>
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 0xfffcdd5eba50>
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 0xfffcdd5eba50>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdd9eb110>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcddbe9f30>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd705650>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdd6f9e50>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd6f8f90>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_109.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_109.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_109.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_109.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_109.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_109.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_109.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_109.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_109.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_109.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_109.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_109.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_109.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_109.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_109.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_109.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_109.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_109.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_109.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_109.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_109.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_109.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_109.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_109.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
_________ ERROR at setup of AppTestBuiltinApp.test_eval_adds_builtins __________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_110.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdd6f5ad0>, 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_eval_adds_builtins'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_eval_adds_builtins'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_eval_adds_builtins'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_eval_adds_builtins'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_eval_adds_builtins'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_eval_adds_builtins'>}
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_eval_adds_builtins'>, '__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 0xfffcdd95c690>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...s_builtins'>, '__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 0xfffcdd95c460>
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 0xfffcdd95c460>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...s_builtins'>, '__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_eval_adds_builtins'>, '__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_eval_adds_builtins'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcddc4a190>
key = (((True, False, False, True, False, 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 0xfffcddc4a190>
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 0xfffcddc4a190>
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 0xfffcddc4a190>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdcb86210>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdd22d360>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd869c90>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdcfd3f50>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdce72bd0>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_110.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_110.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_110.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_110.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_110.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_110.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_110.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_110.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_110.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_110.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_110.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_110.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_110.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_110.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_110.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_110.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_110.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_110.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_110.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_110.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_110.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_110.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_110.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_110.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
_______________ ERROR at setup of AppTestBuiltinApp.test_import ________________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_111.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdd0c6f50>, 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_import'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_import'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_import'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_import'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_import'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_import'>}
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_import'>, '__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 0xfffcdd86c7d0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...est_import'>, '__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 0xfffcdd86c410>
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 0xfffcdd86c410>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...est_import'>, '__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_import'>, '__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_import'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdcc4d450>
key = (((True, False, False, True, False, 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 0xfffcdcc4d450>
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 0xfffcdcc4d450>
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 0xfffcdcc4d450>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcddc7e390>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcddc0de50>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd893610>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdd77c710>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd777750>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_111.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_111.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_111.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_111.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_111.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_111.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_111.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_111.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_111.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_111.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_111.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_111.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_111.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_111.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_111.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_111.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_111.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_111.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_111.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_111.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_111.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_111.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_111.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_111.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
________________ ERROR at setup of AppTestBuiltinApp.test_ascii ________________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_112.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdd898150>, 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_ascii'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_ascii'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_ascii'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_ascii'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_ascii'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_ascii'>}
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_ascii'>, '__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 0xfffcdd0602d0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...test_ascii'>, '__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 0xfffcdd0605a0>
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 0xfffcdd0605a0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...test_ascii'>, '__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_ascii'>, '__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_ascii'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdd28a190>
key = (((True, False, False, True, False, 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 0xfffcdd28a190>
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 0xfffcdd28a190>
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 0xfffcdd28a190>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdd929290>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdcc880c0>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd5c3ed0>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdd93ead0>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdcb1b650>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_112.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_112.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_112.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_112.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_112.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_112.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_112.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_112.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_112.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_112.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_112.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_112.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_112.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_112.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_112.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_112.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_112.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_112.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_112.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_112.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_112.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_112.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_112.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_112.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
_________________ ERROR at setup of AppTestBuiltinApp.test_bin _________________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_113.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdd8bea50>, 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_bin'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_bin'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_bin'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_bin'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_bin'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_bin'>}
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_bin'>, '__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 0xfffcdcb880f0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i... 'test_bin'>, '__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 0xfffcdcb881e0>
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 0xfffcdcb881e0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i... 'test_bin'>, '__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_bin'>, '__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_bin'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdcfe7b10>
key = (((True, False, False, True, False, 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 0xfffcdcfe7b10>
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 0xfffcdcfe7b10>
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 0xfffcdcfe7b10>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdd7c4610>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcddc0aad0>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdcfd3150>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdcfd33d0>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdce72c50>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_113.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_113.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_113.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_113.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_113.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_113.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_113.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_113.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_113.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_113.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_113.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_113.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_113.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_113.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_113.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_113.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_113.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_113.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_113.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_113.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_113.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_113.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_113.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_113.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
_________________ ERROR at setup of AppTestBuiltinApp.test_oct _________________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_114.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdd0adf50>, 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_oct'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_oct'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_oct'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_oct'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_oct'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_oct'>}
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_oct'>, '__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 0xfffcdca6b410>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i... 'test_oct'>, '__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 0xfffcdd58eaa0>
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 0xfffcdd58eaa0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i... 'test_oct'>, '__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_oct'>, '__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_oct'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdcc4dd90>
key = (((True, False, False, True, False, 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 0xfffcdcc4dd90>
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 0xfffcdcc4dd90>
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 0xfffcdcc4dd90>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdcfe26d0>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdd6ea520>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd226190>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdd887bd0>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd0ca490>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_114.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_114.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_114.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_114.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_114.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_114.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_114.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_114.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_114.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_114.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_114.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_114.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_114.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_114.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_114.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_114.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_114.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_114.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_114.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_114.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_114.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_114.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_114.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_114.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
_________________ ERROR at setup of AppTestBuiltinApp.test_hex _________________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_115.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdd6f4a50>, 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_hex'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_hex'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_hex'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_hex'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_hex'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_hex'>}
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_hex'>, '__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 0xfffcdc9154b0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i... 'test_hex'>, '__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 0xfffcdc915280>
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 0xfffcdc915280>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i... 'test_hex'>, '__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_hex'>, '__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_hex'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdcfb1410>
key = (((True, False, False, True, False, 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 0xfffcdcfb1410>
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 0xfffcdcfb1410>
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 0xfffcdcfb1410>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdd739ad0>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdd3e1910>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdcc3cb50>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdd7c74d0>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdc9ef490>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_115.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_115.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_115.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_115.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_115.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_115.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_115.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_115.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_115.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_115.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_115.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_115.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_115.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_115.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_115.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_115.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_115.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_115.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_115.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_115.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_115.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_115.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_115.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_115.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
_________________ ERROR at setup of AppTestBuiltinApp.test_chr _________________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_116.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdd026f50>, 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_chr'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_chr'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_chr'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_chr'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_chr'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_chr'>}
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_chr'>, '__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 0xfffcdcbf2870>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i... 'test_chr'>, '__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 0xfffcdcbf2fa0>
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 0xfffcdcbf2fa0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i... 'test_chr'>, '__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_chr'>, '__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_chr'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdd64bd90>
key = (((True, False, False, True, False, 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 0xfffcdd64bd90>
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 0xfffcdd64bd90>
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 0xfffcdd64bd90>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdd5ccb10>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcddbee440>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcddbe4d50>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcddbe4450>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd508510>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_116.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_116.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_116.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_116.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_116.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_116.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_116.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_116.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_116.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_116.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_116.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_116.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_116.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_116.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_116.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_116.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_116.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_116.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_116.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_116.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_116.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_116.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_116.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_116.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
_______________ ERROR at setup of AppTestBuiltinApp.test_globals _______________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_117.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdd49b0d0>, 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_globals'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_globals'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_globals'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_globals'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_globals'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_globals'>}
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_globals'>, '__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 0xfffcdc6816e0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...st_globals'>, '__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 0xfffcdc681410>
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 0xfffcdc681410>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...st_globals'>, '__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_globals'>, '__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_globals'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdd3f5710>
key = (((True, False, False, True, False, 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 0xfffcdd3f5710>
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 0xfffcdd3f5710>
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 0xfffcdd3f5710>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdd7a7510>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdcc888a0>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd262810>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdcb22450>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd9f4690>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_117.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_117.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_117.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_117.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_117.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_117.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_117.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_117.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_117.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_117.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_117.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_117.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_117.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_117.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_117.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_117.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_117.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_117.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_117.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_117.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_117.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_117.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_117.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_117.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
_______________ ERROR at setup of AppTestBuiltinApp.test_locals ________________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_118.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdd0c5f50>, 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_locals'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_locals'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_locals'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_locals'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_locals'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_locals'>}
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_locals'>, '__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 0xfffcddd39c30>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...est_locals'>, '__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 0xfffcddd39eb0>
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 0xfffcddd39eb0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...est_locals'>, '__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_locals'>, '__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_locals'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdd5bae10>
key = (((True, False, False, True, False, 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 0xfffcdd5bae10>
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 0xfffcdd5bae10>
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 0xfffcdd5bae10>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdda9a650>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdcd3d360>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdcc3c510>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcddc491d0>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdcd6bcd0>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_118.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_118.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_118.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_118.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_118.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_118.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_118.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_118.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_118.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_118.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_118.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_118.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_118.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_118.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_118.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_118.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_118.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_118.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_118.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_118.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_118.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_118.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_118.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_118.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
________ ERROR at setup of AppTestBuiltinApp.test_locals_deleted_local _________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_119.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdcd4cb50>, 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_locals_deleted_local'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_locals_deleted_local'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_locals_deleted_local'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_locals_deleted_local'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_locals_deleted_local'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_locals_deleted_local'>}
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_locals_deleted_local'>, '__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 0xfffcddd1aa00>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...eted_local'>, '__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 0xfffcddd1a9b0>
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 0xfffcddd1a9b0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...eted_local'>, '__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_locals_deleted_local'>, '__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_locals_deleted_local'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdcf2c190>
key = (((True, False, False, True, False, 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 0xfffcdcf2c190>
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 0xfffcdcf2c190>
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 0xfffcdcf2c190>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdd8ca210>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcddbe2830>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd1def90>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdcfcce90>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd1214d0>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_119.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_119.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_119.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_119.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_119.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_119.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_119.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_119.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_119.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_119.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_119.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_119.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_119.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_119.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_119.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_119.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_119.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_119.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_119.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_119.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_119.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_119.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_119.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_119.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
_________________ ERROR at setup of AppTestBuiltinApp.test_dir _________________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_120.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdcd50ed0>, 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_dir'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_dir'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_dir'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_dir'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_dir'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_dir'>}
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_dir'>, '__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 0xfffcdcc0eeb0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i... 'test_dir'>, '__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 0xfffcdcc0ee10>
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 0xfffcdcc0ee10>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i... 'test_dir'>, '__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_dir'>, '__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_dir'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdd32e590>
key = (((True, False, False, True, False, 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 0xfffcdd32e590>
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 0xfffcdd32e590>
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 0xfffcdd32e590>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdd5eb690>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdcd38ec0>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdcb86750>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdcd2ead0>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdce2d490>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_120.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_120.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_120.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_120.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_120.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_120.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_120.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_120.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_120.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_120.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_120.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_120.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_120.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_120.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_120.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_120.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_120.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_120.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_120.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_120.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_120.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_120.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_120.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_120.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
________ ERROR at setup of AppTestBuiltinApp.test_dir_in_broken_locals _________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_121.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcddc67f50>, 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_dir_in_broken_locals'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_dir_in_broken_locals'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_dir_in_broken_locals'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_dir_in_broken_locals'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_dir_in_broken_locals'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_dir_in_broken_locals'>}
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_dir_in_broken_locals'>, '__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 0xfffcddc4f640>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ken_locals'>, '__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 0xfffcddc4fc30>
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 0xfffcddc4fc30>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ken_locals'>, '__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_dir_in_broken_locals'>, '__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_dir_in_broken_locals'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdce9c3d0>
key = (((True, False, False, True, False, 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 0xfffcdce9c3d0>
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 0xfffcdce9c3d0>
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 0xfffcdce9c3d0>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdcf07d50>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdd9e29f0>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd0a8a90>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdda80490>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd002590>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_121.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_121.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_121.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_121.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_121.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_121.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_121.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_121.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_121.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_121.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_121.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_121.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_121.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_121.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_121.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_121.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_121.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_121.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_121.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_121.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_121.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_121.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_121.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_121.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
__________ ERROR at setup of AppTestBuiltinApp.test_dir_broken_module __________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_122.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdda0f250>, 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_dir_broken_module'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_dir_broken_module'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_dir_broken_module'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_dir_broken_module'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_dir_broken_module'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_dir_broken_module'>}
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_dir_broken_module'>, '__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 0xfffcdd952550>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ken_module'>, '__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 0xfffcdd9527d0>
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 0xfffcdd9527d0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ken_module'>, '__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_dir_broken_module'>, '__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_dir_broken_module'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdcce7c10>
key = (((True, False, False, True, False, 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 0xfffcdcce7c10>
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 0xfffcdcce7c10>
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 0xfffcdcce7c10>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdc75ec90>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcddbb96e0>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd2d81d0>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdd2d8350>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd591d90>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_122.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_122.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_122.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_122.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_122.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_122.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_122.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_122.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_122.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_122.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_122.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_122.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_122.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_122.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_122.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_122.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_122.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_122.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_122.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_122.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_122.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_122.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_122.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_122.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
__________ ERROR at setup of AppTestBuiltinApp.test_dir_broken_object __________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_123.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcddbfadd0>, 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_dir_broken_object'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_dir_broken_object'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_dir_broken_object'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_dir_broken_object'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_dir_broken_object'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_dir_broken_object'>}
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_dir_broken_object'>, '__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 0xfffcdd8ecd70>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ken_object'>, '__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 0xfffcdd8ecfa0>
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 0xfffcdd8ecfa0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ken_object'>, '__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_dir_broken_object'>, '__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_dir_broken_object'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdd1fcfd0>
key = (((True, False, False, True, False, 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 0xfffcdd1fcfd0>
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 0xfffcdd1fcfd0>
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 0xfffcdd1fcfd0>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdcfd2550>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdcc6e910>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdcfcc0d0>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdcfcca50>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcddc8cf10>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_123.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_123.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_123.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_123.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_123.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_123.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_123.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_123.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_123.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_123.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_123.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_123.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_123.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_123.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_123.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_123.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_123.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_123.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_123.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_123.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_123.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_123.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_123.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_123.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
_____________ ERROR at setup of AppTestBuiltinApp.test_dir_custom ______________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_124.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdcc86a50>, 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_dir_custom'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_dir_custom'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_dir_custom'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_dir_custom'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_dir_custom'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_dir_custom'>}
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_dir_custom'>, '__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 0xfffcdcbc8b90>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...dir_custom'>, '__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 0xfffcdcbc8dc0>
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 0xfffcdcbc8dc0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...dir_custom'>, '__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_dir_custom'>, '__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_dir_custom'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdc9ff710>
key = (((True, False, False, True, False, 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 0xfffcdc9ff710>
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 0xfffcdc9ff710>
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 0xfffcdc9ff710>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdcae6c50>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdcc151a0>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd897790>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdcad2bd0>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcddbe4090>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_124.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_124.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_124.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_124.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_124.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_124.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_124.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_124.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_124.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_124.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_124.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_124.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_124.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_124.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_124.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_124.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_124.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_124.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_124.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_124.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_124.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_124.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_124.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_124.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
__________ ERROR at setup of AppTestBuiltinApp.test_dir_custom_lookup __________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_125.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdd46fe50>, 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_dir_custom_lookup'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_dir_custom_lookup'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_dir_custom_lookup'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_dir_custom_lookup'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_dir_custom_lookup'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_dir_custom_lookup'>}
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_dir_custom_lookup'>, '__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 0xfffcdcad05a0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...tom_lookup'>, '__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 0xfffcdcad05f0>
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 0xfffcdcad05f0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...tom_lookup'>, '__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_dir_custom_lookup'>, '__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_dir_custom_lookup'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdd3f5310>
key = (((True, False, False, True, False, 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 0xfffcdd3f5310>
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 0xfffcdd3f5310>
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 0xfffcdd3f5310>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdd796410>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdd49a4b0>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdcc97a90>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdd0b1810>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdcd24dd0>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_125.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_125.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_125.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_125.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_125.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_125.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_125.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_125.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_125.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_125.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_125.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_125.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_125.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_125.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_125.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_125.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_125.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_125.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_125.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_125.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_125.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_125.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_125.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_125.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
_______________ ERROR at setup of AppTestBuiltinApp.test_format ________________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_126.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdd474dd0>, 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_format'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_format'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_format'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_format'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_format'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_format'>}
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_format'>, '__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 0xfffcdcaefb40>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...est_format'>, '__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 0xfffcdcaef460>
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 0xfffcdcaef460>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...est_format'>, '__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_format'>, '__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_format'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdce16150>
key = (((True, False, False, True, False, 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 0xfffcdce16150>
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 0xfffcdce16150>
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 0xfffcdce16150>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcddc49590>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdcdd0fa0>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd24a690>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdd6e5210>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdcb689d0>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_126.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_126.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_126.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_126.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_126.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_126.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_126.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_126.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_126.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_126.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_126.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_126.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_126.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_126.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_126.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_126.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_126.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_126.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_126.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_126.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_126.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_126.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_126.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_126.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
________________ ERROR at setup of AppTestBuiltinApp.test_vars _________________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_127.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdcea6250>, 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_vars'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_vars'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_vars'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_vars'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_vars'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_vars'>}
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_vars'>, '__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 0xfffcdc859d70>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...'test_vars'>, '__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 0xfffcdc859c80>
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 0xfffcdc859c80>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...'test_vars'>, '__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_vars'>, '__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_vars'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdd517f90>
key = (((True, False, False, True, False, 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 0xfffcdd517f90>
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 0xfffcdd517f90>
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 0xfffcdd517f90>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcddbf3110>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdda0a590>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd5cc110>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcddcfb890>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd9f4410>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_127.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_127.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_127.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_127.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_127.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_127.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_127.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_127.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_127.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_127.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_127.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_127.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_127.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_127.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_127.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_127.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_127.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_127.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_127.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_127.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_127.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_127.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_127.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_127.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
_________________ ERROR at setup of AppTestBuiltinApp.test_sum _________________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_128.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdda12dd0>, 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_sum'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_sum'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_sum'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_sum'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_sum'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_sum'>}
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_sum'>, '__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 0xfffcdc6f0b40>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i... 'test_sum'>, '__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 0xfffcdc6f0820>
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 0xfffcdc6f0820>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i... 'test_sum'>, '__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_sum'>, '__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_sum'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdcbf3d10>
key = (((True, False, False, True, False, 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 0xfffcdcbf3d10>
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 0xfffcdcbf3d10>
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 0xfffcdcbf3d10>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdcd80ed0>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdcaf4ec0>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd932990>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdd8e7390>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdc98d310>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_128.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_128.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_128.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_128.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_128.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_128.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_128.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_128.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_128.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_128.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_128.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_128.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_128.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_128.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_128.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_128.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_128.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_128.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_128.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_128.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_128.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_128.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_128.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_128.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
____________ ERROR at setup of AppTestBuiltinApp.test_sum_fast_path ____________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_129.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdcc86750>, 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_sum_fast_path'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_sum_fast_path'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_sum_fast_path'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_sum_fast_path'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_sum_fast_path'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_sum_fast_path'>}
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_sum_fast_path'>, '__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 0xfffcdca4b460>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._fast_path'>, '__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 0xfffcdca4b550>
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 0xfffcdca4b550>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._fast_path'>, '__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_sum_fast_path'>, '__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_sum_fast_path'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdce72d50>
key = (((True, False, False, True, False, 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 0xfffcdce72d50>
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 0xfffcdce72d50>
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 0xfffcdce72d50>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdd866490>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdd61ac90>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd6997d0>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdd35f250>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd739850>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_129.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_129.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_129.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_129.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_129.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_129.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_129.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_129.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_129.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_129.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_129.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_129.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_129.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_129.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_129.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_129.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_129.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_129.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_129.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_129.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_129.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_129.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_129.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_129.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
________ ERROR at setup of AppTestBuiltinApp.test_sum_empty_edge_cases _________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_130.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdcdb9a50>, 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_sum_empty_edge_cases'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_sum_empty_edge_cases'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_sum_empty_edge_cases'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_sum_empty_edge_cases'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_sum_empty_edge_cases'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_sum_empty_edge_cases'>}
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_sum_empty_edge_cases'>, '__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 0xfffcdc6435a0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...edge_cases'>, '__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 0xfffcdc643280>
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 0xfffcdc643280>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...edge_cases'>, '__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_sum_empty_edge_cases'>, '__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_sum_empty_edge_cases'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdd1fc910>
key = (((True, False, False, True, False, 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 0xfffcdd1fc910>
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 0xfffcdd1fc910>
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 0xfffcdd1fc910>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdd879710>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcddd12a60>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdcb1a410>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdc8deb90>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd9eb710>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_130.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_130.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_130.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_130.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_130.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_130.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_130.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_130.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_130.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_130.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_130.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_130.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_130.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_130.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_130.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_130.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_130.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_130.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_130.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_130.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_130.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_130.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_130.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_130.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
___________ ERROR at setup of AppTestBuiltinApp.test_sum_type_errors ___________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_131.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcddd1ee50>, 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_sum_type_errors'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_sum_type_errors'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_sum_type_errors'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_sum_type_errors'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_sum_type_errors'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_sum_type_errors'>}
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_sum_type_errors'>, '__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 0xfffcdccf4910>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ype_errors'>, '__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 0xfffcdcb5ae60>
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 0xfffcdcb5ae60>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ype_errors'>, '__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_sum_type_errors'>, '__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_sum_type_errors'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdce57410>
key = (((True, False, False, True, False, 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 0xfffcdce57410>
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 0xfffcdce57410>
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 0xfffcdce57410>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdd7b6ad0>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdce40590>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdc827890>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdcb1ef90>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdcce7cd0>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_131.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_131.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_131.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_131.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_131.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_131.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_131.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_131.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_131.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_131.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_131.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_131.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_131.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_131.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_131.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_131.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_131.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_131.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_131.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_131.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_131.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_131.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_131.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_131.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
_________ ERROR at setup of AppTestBuiltinApp.test_sum_strange_objects _________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_132.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdd080350>, 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_sum_strange_objects'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_sum_strange_objects'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_sum_strange_objects'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_sum_strange_objects'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_sum_strange_objects'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_sum_strange_objects'>}
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_sum_strange_objects'>, '__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 0xfffcdcc7ed70>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ge_objects'>, '__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 0xfffcdcc7e320>
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 0xfffcdcc7e320>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ge_objects'>, '__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_sum_strange_objects'>, '__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_sum_strange_objects'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdc769a50>
key = (((True, False, False, True, False, 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 0xfffcdc769a50>
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 0xfffcdc769a50>
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 0xfffcdc769a50>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdd6e5310>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcddd12750>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd5eb7d0>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdd777390>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdcef63d0>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_132.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_132.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_132.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_132.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_132.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_132.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_132.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_132.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_132.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_132.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_132.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_132.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_132.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_132.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_132.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_132.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_132.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_132.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_132.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_132.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_132.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_132.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_132.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_132.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
_____ ERROR at setup of AppTestBuiltinApp.test_sum_first_object_edge_cases _____
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_133.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdcdaddd0>, 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_sum_first_object_edge_cases'>, ...ticall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_sum_first_object_edge_cases'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_sum_first_object_edge_cases'>, ...ticall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_sum_first_object_edge_cases'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_sum_first_object_edge_cases'>, ...ticall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_sum_first_object_edge_cases'>}
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_sum_first_object_edge_cases'>, '__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 0xfffcdc92e7d0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...edge_cases'>, '__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 0xfffcdc92e870>
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 0xfffcdc92e870>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...edge_cases'>, '__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_sum_first_object_edge_cases'>, '__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_sum_first_object_edge_cases'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdcf47190>
key = (((True, False, False, True, False, 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 0xfffcdcf47190>
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 0xfffcdcf47190>
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 0xfffcdcf47190>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcddbe5210>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdd5ff4b0>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd213a90>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdcf273d0>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcddd2a4d0>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_133.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_133.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_133.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_133.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_133.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_133.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_133.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_133.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_133.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_133.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_133.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_133.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_133.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_133.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_133.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_133.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_133.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_133.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_133.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_133.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_133.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_133.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_133.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_133.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
____________ ERROR at setup of AppTestBuiltinApp.test_type_selftest ____________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_134.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdd6126d0>, 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_type_selftest'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_type_selftest'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_type_selftest'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_type_selftest'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_type_selftest'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_type_selftest'>}
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_type_selftest'>, '__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 0xfffcddc7bf50>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...e_selftest'>, '__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 0xfffcddc7bb90>
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 0xfffcddc7bb90>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...e_selftest'>, '__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_type_selftest'>, '__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_type_selftest'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdcff7690>
key = (((True, False, False, True, False, 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 0xfffcdcff7690>
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 0xfffcdcff7690>
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 0xfffcdcff7690>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcddc7e990>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdda1c3d0>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcddcbf810>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdda6b990>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdc66cf10>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_134.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_134.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_134.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_134.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_134.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_134.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_134.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_134.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_134.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_134.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_134.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_134.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_134.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_134.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_134.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_134.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_134.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_134.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_134.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_134.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_134.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_134.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_134.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_134.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
____________ ERROR at setup of AppTestBuiltinApp.test_iter_sequence ____________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_135.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdd5fed50>, 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_iter_sequence'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_iter_sequence'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_iter_sequence'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_iter_sequence'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_iter_sequence'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_iter_sequence'>}
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_iter_sequence'>, '__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 0xfffcdd39f690>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...r_sequence'>, '__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 0xfffcdd39feb0>
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 0xfffcdd39feb0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...r_sequence'>, '__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_iter_sequence'>, '__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_iter_sequence'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdce72a50>
key = (((True, False, False, True, False, 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 0xfffcdce72a50>
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 0xfffcdce72a50>
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 0xfffcdce72a50>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdca17450>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdd64fde0>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdc560bd0>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdd404750>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd866750>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_135.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_135.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_135.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_135.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_135.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_135.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_135.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_135.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_135.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_135.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_135.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_135.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_135.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_135.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_135.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_135.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_135.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_135.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_135.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_135.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_135.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_135.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_135.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_135.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
____________ ERROR at setup of AppTestBuiltinApp.test_iter___iter__ ____________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_136.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcddc2d0d0>, 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_iter___iter__'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_iter___iter__'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_iter___iter__'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_iter___iter__'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_iter___iter__'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_iter___iter__'>}
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_iter___iter__'>, '__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 0xfffcdd5ee3c0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...r___iter__'>, '__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 0xfffcdd5eea50>
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 0xfffcdd5eea50>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...r___iter__'>, '__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_iter___iter__'>, '__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_iter___iter__'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdc4c4650>
key = (((True, False, False, True, False, 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 0xfffcdc4c4650>
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 0xfffcdc4c4650>
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 0xfffcdc4c4650>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdd213290>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdc406d00>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdcb1ee90>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdcce7cd0>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd5c3910>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_136.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_136.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_136.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_136.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_136.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_136.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_136.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_136.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_136.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_136.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_136.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_136.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_136.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_136.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_136.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_136.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_136.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_136.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_136.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_136.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_136.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_136.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_136.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_136.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
_______ ERROR at setup of AppTestBuiltinApp.test_iter_callable_sentinel ________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_137.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdd06ad50>, 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_iter_callable_sentinel'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_iter_callable_sentinel'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_iter_callable_sentinel'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_iter_callable_sentinel'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_iter_callable_sentinel'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_iter_callable_sentinel'>}
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_iter_callable_sentinel'>, '__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 0xfffcdd77dc30>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...e_sentinel'>, '__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 0xfffcdd77dd70>
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 0xfffcdd77dd70>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...e_sentinel'>, '__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_iter_callable_sentinel'>, '__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_iter_callable_sentinel'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdcfcc750>
key = (((True, False, False, True, False, 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 0xfffcdcfcc750>
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 0xfffcdcfcc750>
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 0xfffcdcfcc750>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdccb7350>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdd07ef30>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcddbc4710>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdd655d90>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdcb73810>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_137.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_137.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_137.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_137.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_137.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_137.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_137.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_137.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_137.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_137.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_137.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_137.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_137.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_137.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_137.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_137.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_137.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_137.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_137.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_137.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_137.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_137.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_137.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_137.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
______________ ERROR at setup of AppTestBuiltinApp.test_enumerate ______________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_138.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdd06df50>, 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_enumerate'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_enumerate'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_enumerate'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_enumerate'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_enumerate'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_enumerate'>}
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_enumerate'>, '__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 0xfffcdd067960>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._enumerate'>, '__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 0xfffcdd067b90>
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 0xfffcdd067b90>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._enumerate'>, '__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_enumerate'>, '__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_enumerate'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdc87f810>
key = (((True, False, False, True, False, 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 0xfffcdc87f810>
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 0xfffcdc87f810>
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 0xfffcdc87f810>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcddbbe950>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdc905a60>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd275e50>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcddc1a150>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd2a8490>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_138.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_138.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_138.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_138.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_138.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_138.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_138.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_138.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_138.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_138.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_138.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_138.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_138.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_138.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_138.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_138.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_138.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_138.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_138.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_138.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_138.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_138.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_138.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_138.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
________________ ERROR at setup of AppTestBuiltinApp.test_next _________________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_139.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdc8e85d0>, 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_next'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_next'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_next'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_next'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_next'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_next'>}
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_next'>, '__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 0xfffcdc9ebf50>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...'test_next'>, '__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 0xfffcdc9eb410>
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 0xfffcdc9eb410>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...'test_next'>, '__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_next'>, '__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_next'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdd93d1d0>
key = (((True, False, False, True, False, 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 0xfffcdd93d1d0>
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 0xfffcdd93d1d0>
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 0xfffcdd93d1d0>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdc8db890>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdd07e280>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcddd432d0>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdd336410>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcddbf3290>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_139.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_139.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_139.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_139.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_139.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_139.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_139.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_139.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_139.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_139.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_139.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_139.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_139.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_139.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_139.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_139.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_139.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_139.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_139.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_139.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_139.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_139.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_139.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_139.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
____________ ERROR at setup of AppTestBuiltinApp.test_next__next__ _____________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_140.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdda0ecd0>, 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_next__next__'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_next__next__'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_next__next__'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_next__next__'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_next__next__'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_next__next__'>}
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_next__next__'>, '__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 0xfffcdcebd7d0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...xt__next__'>, '__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 0xfffcdcebd730>
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 0xfffcdcebd730>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...xt__next__'>, '__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_next__next__'>, '__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_next__next__'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdd32e810>
key = (((True, False, False, True, False, 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 0xfffcdd32e810>
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 0xfffcdd32e810>
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 0xfffcdd32e810>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdcbc0f10>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdc905670>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdca2c110>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdca2cc10>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdcd6b610>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_140.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_140.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_140.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_140.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_140.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_140.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_140.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_140.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_140.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_140.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_140.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_140.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_140.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_140.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_140.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_140.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_140.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_140.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_140.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_140.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_140.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_140.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_140.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_140.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
_____________ ERROR at setup of AppTestBuiltinApp.test_range_args ______________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_141.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdd60af50>, 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_range_args'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_range_args'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_range_args'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_range_args'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_range_args'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_range_args'>}
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_range_args'>, '__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 0xfffcdcd72b90>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...range_args'>, '__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 0xfffcdcd72dc0>
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 0xfffcdcd72dc0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...range_args'>, '__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_range_args'>, '__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_range_args'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdce93250>
key = (((True, False, False, True, False, 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 0xfffcdce93250>
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 0xfffcdce93250>
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 0xfffcdce93250>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdc87f650>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdc766130>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd00c9d0>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdd783410>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdcca36d0>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_141.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_141.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_141.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_141.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_141.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_141.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_141.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_141.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_141.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_141.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_141.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_141.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_141.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_141.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_141.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_141.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_141.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_141.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_141.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_141.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_141.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_141.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_141.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_141.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
_____________ ERROR at setup of AppTestBuiltinApp.test_range_repr ______________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_142.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdd3275d0>, 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_range_repr'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_range_repr'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_range_repr'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_range_repr'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_range_repr'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_range_repr'>}
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_range_repr'>, '__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 0xfffcdc9067d0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...range_repr'>, '__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 0xfffcdc906aa0>
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 0xfffcdc906aa0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...range_repr'>, '__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_range_repr'>, '__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_range_repr'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdcfcc0d0>
key = (((True, False, False, True, False, 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 0xfffcdcfcc0d0>
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 0xfffcdcfcc0d0>
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 0xfffcdcfcc0d0>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdc9db310>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdcc03520>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd336410>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdd3360d0>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcddd43fd0>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_142.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_142.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_142.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_142.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_142.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_142.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_142.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_142.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_142.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_142.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_142.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_142.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_142.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_142.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_142.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_142.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_142.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_142.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_142.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_142.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_142.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_142.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_142.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_142.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
______________ ERROR at setup of AppTestBuiltinApp.test_range_up _______________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_143.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdcbfbf50>, 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_range_up'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_range_up'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_range_up'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_range_up'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_range_up'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_range_up'>}
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_range_up'>, '__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 0xfffcdce8f140>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_range_up'>, '__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 0xfffcdcb5a280>
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 0xfffcdcb5a280>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_range_up'>, '__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_range_up'>, '__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_range_up'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdcc43fd0>
key = (((True, False, False, True, False, 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 0xfffcdcc43fd0>
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 0xfffcdcc43fd0>
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 0xfffcdcc43fd0>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdd226190>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdcf61050>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdcff7650>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdd0d7450>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdcd29150>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_143.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_143.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_143.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_143.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_143.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_143.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_143.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_143.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_143.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_143.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_143.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_143.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_143.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_143.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_143.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_143.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_143.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_143.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_143.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_143.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_143.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_143.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_143.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_143.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
_____________ ERROR at setup of AppTestBuiltinApp.test_range_down ______________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_144.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdd79a5d0>, 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_range_down'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_range_down'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_range_down'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_range_down'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_range_down'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_range_down'>}
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_range_down'>, '__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 0xfffcdd14b820>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...range_down'>, '__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 0xfffcdd14b960>
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 0xfffcdd14b960>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...range_down'>, '__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_range_down'>, '__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_range_down'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdd603890>
key = (((True, False, False, True, False, 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 0xfffcdd603890>
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 0xfffcdd603890>
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 0xfffcdd603890>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdcb68b50>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdca34980>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd8e7650>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdd758890>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdcad2f10>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_144.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_144.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_144.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_144.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_144.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_144.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_144.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_144.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_144.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_144.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_144.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_144.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_144.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_144.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_144.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_144.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_144.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_144.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_144.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_144.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_144.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_144.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_144.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_144.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
_______ ERROR at setup of AppTestBuiltinApp.test_range_has_type_identity _______
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_145.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdd79df50>, 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_range_has_type_identity'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_range_has_type_identity'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_range_has_type_identity'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_range_has_type_identity'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_range_has_type_identity'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_range_has_type_identity'>}
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_range_has_type_identity'>, '__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 0xfffcdd678640>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...e_identity'>, '__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 0xfffcdd678f50>
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 0xfffcdd678f50>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...e_identity'>, '__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_range_has_type_identity'>, '__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_range_has_type_identity'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdc7ee390>
key = (((True, False, False, True, False, 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 0xfffcdc7ee390>
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 0xfffcdc7ee390>
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 0xfffcdc7ee390>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcddd01350>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdc881f30>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdccb7310>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdcc5e3d0>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd77cbd0>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_145.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_145.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_145.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_145.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_145.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_145.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_145.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_145.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_145.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_145.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_145.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_145.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_145.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_145.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_145.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_145.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_145.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_145.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_145.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_145.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_145.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_145.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_145.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_145.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
______________ ERROR at setup of AppTestBuiltinApp.test_range_len ______________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_146.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdc88f450>, 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_range_len'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_range_len'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_range_len'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_range_len'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_range_len'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_range_len'>}
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_range_len'>, '__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 0xfffcdd3887d0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._range_len'>, '__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 0xfffcdd388b90>
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 0xfffcdd388b90>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._range_len'>, '__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_range_len'>, '__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_range_len'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdc26b190>
key = (((True, False, False, True, False, 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 0xfffcdc26b190>
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 0xfffcdc26b190>
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 0xfffcdc26b190>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdd049cd0>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdca45fa0>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdcb10b10>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdd0ca910>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdcfb1510>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_146.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_146.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_146.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_146.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_146.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_146.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_146.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_146.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_146.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_146.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_146.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_146.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_146.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_146.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_146.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_146.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_146.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_146.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_146.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_146.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_146.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_146.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_146.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_146.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
___________ ERROR at setup of AppTestBuiltinApp.test_range_indexing ____________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_147.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdc772c50>, 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_range_indexing'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_range_indexing'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_range_indexing'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_range_indexing'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_range_indexing'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_range_indexing'>}
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_range_indexing'>, '__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 0xfffcdc413280>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...e_indexing'>, '__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 0xfffcdc413960>
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 0xfffcdc413960>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...e_indexing'>, '__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_range_indexing'>, '__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_range_indexing'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdc4e9550>
key = (((True, False, False, True, False, 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 0xfffcdc4e9550>
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 0xfffcdc4e9550>
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 0xfffcdc4e9550>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdd941990>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdc782ad0>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd2a8350>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdd2a8150>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdccab710>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_147.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_147.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_147.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_147.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_147.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_147.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_147.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_147.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_147.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_147.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_147.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_147.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_147.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_147.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_147.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_147.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_147.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_147.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_147.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_147.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_147.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_147.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_147.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_147.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
___________ ERROR at setup of AppTestBuiltinApp.test_range_bad_args ____________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_148.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdc77ced0>, 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_range_bad_args'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_range_bad_args'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_range_bad_args'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_range_bad_args'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_range_bad_args'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_range_bad_args'>}
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_range_bad_args'>, '__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 0xfffcdc5b6a50>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...e_bad_args'>, '__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 0xfffcdc5b6be0>
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 0xfffcdc5b6be0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...e_bad_args'>, '__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_range_bad_args'>, '__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_range_bad_args'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdcc780d0>
key = (((True, False, False, True, False, 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 0xfffcdcc780d0>
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 0xfffcdcc780d0>
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 0xfffcdcc780d0>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdd05dd90>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcddc21600>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdcf715d0>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdc7d2b90>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdc4e3ed0>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_148.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_148.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_148.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_148.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_148.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_148.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_148.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_148.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_148.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_148.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_148.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_148.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_148.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_148.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_148.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_148.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_148.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_148.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_148.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_148.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_148.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_148.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_148.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_148.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
_____________ ERROR at setup of AppTestBuiltinApp.test_range_bool ______________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_149.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcddc20450>, 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_range_bool'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_range_bool'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_range_bool'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_range_bool'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_range_bool'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_range_bool'>}
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_range_bool'>, '__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 0xfffcdcac7280>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...range_bool'>, '__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 0xfffcdcac7690>
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 0xfffcdcac7690>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...range_bool'>, '__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_range_bool'>, '__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_range_bool'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcddbda190>
key = (((True, False, False, True, False, 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 0xfffcddbda190>
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 0xfffcddbda190>
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 0xfffcddbda190>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdcb1e550>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdcf06c20>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdc92c290>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdccb36d0>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdc2786d0>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_149.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_149.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_149.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_149.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_149.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_149.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_149.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_149.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_149.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_149.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_149.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_149.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_149.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_149.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_149.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_149.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_149.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_149.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_149.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_149.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_149.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_149.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_149.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_149.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
___________ ERROR at setup of AppTestBuiltinApp.test_range_bool_arg ____________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_150.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdc8f7ed0>, 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_range_bool_arg'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_range_bool_arg'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_range_bool_arg'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_range_bool_arg'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_range_bool_arg'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_range_bool_arg'>}
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_range_bool_arg'>, '__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 0xfffcdcbd58c0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...e_bool_arg'>, '__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 0xfffcdcbd55a0>
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 0xfffcdcbd55a0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...e_bool_arg'>, '__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_range_bool_arg'>, '__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_range_bool_arg'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdce6f250>
key = (((True, False, False, True, False, 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 0xfffcdce6f250>
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 0xfffcdce6f250>
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 0xfffcdce6f250>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdc82ded0>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdd2ce520>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdc52add0>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdd0cc450>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdca12dd0>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_150.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_150.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_150.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_150.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_150.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_150.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_150.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_150.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_150.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_150.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_150.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_150.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_150.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_150.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_150.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_150.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_150.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_150.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_150.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_150.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_150.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_150.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_150.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_150.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
_______________ ERROR at setup of AppTestBuiltinApp.test_sorted ________________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_151.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdc943750>, 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_sorted'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_sorted'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_sorted'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_sorted'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_sorted'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_sorted'>}
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_sorted'>, '__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 0xfffcdc6cd780>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...est_sorted'>, '__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 0xfffcdc6cd8c0>
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 0xfffcdc6cd8c0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...est_sorted'>, '__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_sorted'>, '__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_sorted'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdd0770d0>
key = (((True, False, False, True, False, 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 0xfffcdd0770d0>
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 0xfffcdd0770d0>
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 0xfffcdd0770d0>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdd655f90>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdc782d70>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd8b4290>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdd8b4ad0>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd6390d0>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_151.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_151.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_151.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_151.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_151.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_151.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_151.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_151.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_151.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_151.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_151.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_151.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_151.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_151.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_151.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_151.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_151.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_151.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_151.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_151.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_151.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_151.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_151.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_151.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
________ ERROR at setup of AppTestBuiltinApp.test_sorted_with_keywords _________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_152.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdc8f7d50>, 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_sorted_with_keywords'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_sorted_with_keywords'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_sorted_with_keywords'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_sorted_with_keywords'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_sorted_with_keywords'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_sorted_with_keywords'>}
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_sorted_with_keywords'>, '__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 0xfffcdd26a3c0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...h_keywords'>, '__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 0xfffcdd26a780>
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 0xfffcdd26a780>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...h_keywords'>, '__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_sorted_with_keywords'>, '__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_sorted_with_keywords'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdce579d0>
key = (((True, False, False, True, False, 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 0xfffcdce579d0>
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 0xfffcdce579d0>
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 0xfffcdce579d0>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcddd01d10>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdc7cac20>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcddcbf710>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcddcbf3d0>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcddd00150>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_152.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_152.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_152.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_152.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_152.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_152.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_152.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_152.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_152.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_152.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_152.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_152.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_152.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_152.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_152.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_152.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_152.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_152.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_152.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_152.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_152.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_152.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_152.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_152.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
__________ ERROR at setup of AppTestBuiltinApp.test_sorted_posonlyarg __________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_153.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcddc46e50>, 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_sorted_posonlyarg'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_sorted_posonlyarg'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_sorted_posonlyarg'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_sorted_posonlyarg'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_sorted_posonlyarg'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_sorted_posonlyarg'>}
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_sorted_posonlyarg'>, '__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 0xfffcdc49bb40>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...posonlyarg'>, '__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 0xfffcdc49b820>
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 0xfffcdc49b820>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...posonlyarg'>, '__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_sorted_posonlyarg'>, '__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_sorted_posonlyarg'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdc65e990>
key = (((True, False, False, True, False, 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 0xfffcdc65e990>
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 0xfffcdc65e990>
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 0xfffcdc65e990>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcddd3ae90>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcddccfbb0>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd86f6d0>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdce64290>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd8795d0>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_153.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_153.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_153.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_153.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_153.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_153.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_153.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_153.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_153.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_153.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_153.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_153.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_153.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_153.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_153.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_153.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_153.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_153.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_153.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_153.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_153.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_153.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_153.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_153.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
______ ERROR at setup of AppTestBuiltinApp.test_reversed_simple_sequences ______
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_154.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdda6f3d0>, 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_reversed_simple_sequences'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_reversed_simple_sequences'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_reversed_simple_sequences'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_reversed_simple_sequences'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_reversed_simple_sequences'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_reversed_simple_sequences'>}
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_reversed_simple_sequences'>, '__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 0xfffcdc76a2d0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._sequences'>, '__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 0xfffcdc76a730>
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 0xfffcdc76a730>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._sequences'>, '__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_reversed_simple_sequences'>, '__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_reversed_simple_sequences'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdd340e90>
key = (((True, False, False, True, False, 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 0xfffcdd340e90>
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 0xfffcdd340e90>
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 0xfffcdd340e90>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdcf473d0>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdca24590>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd881350>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdd05d110>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdcc788d0>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_154.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_154.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_154.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_154.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_154.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_154.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_154.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_154.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_154.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_154.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_154.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_154.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_154.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_154.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_154.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_154.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_154.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_154.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_154.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_154.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_154.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_154.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_154.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_154.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
_______ ERROR at setup of AppTestBuiltinApp.test_reversed_custom_objects _______
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_155.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdcab5dd0>, 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_reversed_custom_objects'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_reversed_custom_objects'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_reversed_custom_objects'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_reversed_custom_objects'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_reversed_custom_objects'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_reversed_custom_objects'>}
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_reversed_custom_objects'>, '__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 0xfffcdc2275f0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...om_objects'>, '__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 0xfffcdc2273c0>
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 0xfffcdc2273c0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...om_objects'>, '__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_reversed_custom_objects'>, '__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_reversed_custom_objects'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdc3ddd90>
key = (((True, False, False, True, False, 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 0xfffcdc3ddd90>
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 0xfffcdc3ddd90>
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 0xfffcdc3ddd90>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcddd27bd0>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdd5d5ad0>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdc02f190>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdca79110>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd47b490>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_155.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_155.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_155.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_155.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_155.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_155.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_155.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_155.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_155.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_155.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_155.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_155.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_155.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_155.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_155.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_155.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_155.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_155.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_155.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_155.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_155.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_155.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_155.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_155.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
_____________ ERROR at setup of AppTestBuiltinApp.test_return_None _____________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_156.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdd5c9ad0>, 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_return_None'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_return_None'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_return_None'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_return_None'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_return_None'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_return_None'>}
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_return_None'>, '__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 0xfffcddc54190>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...eturn_None'>, '__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 0xfffcddc548c0>
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 0xfffcddc548c0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...eturn_None'>, '__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_return_None'>, '__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_return_None'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdcbc0150>
key = (((True, False, False, True, False, 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 0xfffcdcbc0150>
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 0xfffcdcbc0150>
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 0xfffcdcbc0150>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcddbfed90>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdc7b2fa0>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdc8db8d0>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdcb1eed0>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdcf27d50>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_156.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_156.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_156.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_156.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_156.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_156.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_156.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_156.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_156.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_156.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_156.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_156.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_156.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_156.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_156.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_156.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_156.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_156.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_156.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_156.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_156.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_156.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_156.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_156.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
_______________ ERROR at setup of AppTestBuiltinApp.test_divmod ________________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_157.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdd5bbd50>, 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_divmod'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_divmod'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_divmod'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_divmod'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_divmod'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_divmod'>}
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_divmod'>, '__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 0xfffcdc2e68c0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...est_divmod'>, '__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 0xfffcdc2e6460>
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 0xfffcdc2e6460>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...est_divmod'>, '__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_divmod'>, '__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_divmod'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdd78d590>
key = (((True, False, False, True, False, 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 0xfffcdd78d590>
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 0xfffcdd78d590>
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 0xfffcdd78d590>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdd0d7490>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcddd379f0>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdc886ad0>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdc886850>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdc754450>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_157.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_157.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_157.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_157.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_157.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_157.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_157.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_157.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_157.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_157.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_157.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_157.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_157.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_157.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_157.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_157.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_157.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_157.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_157.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_157.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_157.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_157.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_157.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_157.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
______________ ERROR at setup of AppTestBuiltinApp.test_callable _______________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_158.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdd201e50>, 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_callable'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_callable'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_callable'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_callable'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_callable'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_callable'>}
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_callable'>, '__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 0xfffcdc33cf50>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_callable'>, '__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 0xfffcdc33cf00>
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 0xfffcdc33cf00>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_callable'>, '__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_callable'>, '__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_callable'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdc900d50>
key = (((True, False, False, True, False, 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 0xfffcdc900d50>
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 0xfffcdc900d50>
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 0xfffcdc900d50>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdd330510>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdda8d360>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdc4b7990>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdcc272d0>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdd655e50>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_158.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_158.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_158.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_158.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_158.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_158.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_158.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_158.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_158.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_158.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_158.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_158.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_158.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_158.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_158.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_158.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_158.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_158.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_158.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_158.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_158.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_158.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_158.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_158.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
_____________ ERROR at setup of AppTestBuiltinApp.test_uncallable ______________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_159.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdc93bad0>, 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_uncallable'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_uncallable'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_uncallable'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_uncallable'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_uncallable'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_uncallable'>}
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_uncallable'>, '__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 0xfffcdc4e15a0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...uncallable'>, '__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 0xfffcdc4e1be0>
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 0xfffcdc4e1be0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...uncallable'>, '__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_uncallable'>, '__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_uncallable'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdda98d50>
key = (((True, False, False, True, False, 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 0xfffcdda98d50>
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 0xfffcdda98d50>
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 0xfffcdda98d50>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdd893f50>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdd947590>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdc746090>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdc746610>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdcc3cc90>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_159.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_159.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_159.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_159.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_159.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_159.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_159.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_159.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_159.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_159.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_159.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_159.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_159.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_159.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_159.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_159.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_159.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_159.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_159.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_159.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_159.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_159.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_159.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_159.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
________________ ERROR at setup of AppTestBuiltinApp.test_hash _________________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_160.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdd942d50>, 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_hash'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_hash'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_hash'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_hash'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_hash'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_hash'>}
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_hash'>, '__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 0xfffcdd151050>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...'test_hash'>, '__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 0xfffcdd151190>
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 0xfffcdd151190>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...'test_hash'>, '__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_hash'>, '__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_hash'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdc5647d0>
key = (((True, False, False, True, False, 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 0xfffcdc5647d0>
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 0xfffcdc5647d0>
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 0xfffcdc5647d0>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdc45ad90>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcdc5970c0>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdce9cfd0>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdd77cc50>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdc560c90>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_160.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_160.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_160.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_160.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_160.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_160.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_160.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_160.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_160.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_160.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_160.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_160.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_160.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_160.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_160.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_160.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_160.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_160.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_160.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_160.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_160.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_160.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_160.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_160.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
________________ ERROR at setup of AppTestBuiltinApp.test_eval _________________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_161.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdccf0550>, 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_eval'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_eval'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_eval'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_eval'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_eval'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_eval'>}
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_eval'>, '__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 0xfffcdc8165a0>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...'test_eval'>, '__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 0xfffcdc816780>
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 0xfffcdc816780>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...'test_eval'>, '__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_eval'>, '__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_eval'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdcc78d90>
key = (((True, False, False, True, False, 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 0xfffcdcc78d90>
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 0xfffcdcc78d90>
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 0xfffcdcc78d90>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdd8ca290>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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))
../rpython/rlib/_rsocket_rffi.py:1222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
CConfig = <class rpython.rlib._rsocket_rffi.CConfig at 0xfffcddcb29f0>
ignore_errors = False
def configure(CConfig, ignore_errors=False):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
what should be inspected; configure() returns a dict mapping
names to the results.
"""
for attr in ['_includes_', '_libraries_', '_sources_', '_library_dirs_',
'_include_dirs_', '_header_']:
assert not hasattr(CConfig, attr), \
"Found legacy attribute %s on CConfig" % attr
eci = CConfig._compilation_info_
entries = {}
for key in dir(CConfig):
value = getattr(CConfig, key)
if isinstance(value, CConfigEntry):
entries[key] = value
res = {}
if entries: # can be empty if there are only CConfigSingleEntries
results = configure_entries(
entries.values(), eci, ignore_errors=ignore_errors)
> for name, result in zip(entries, results):
../rpython/rtyper/tool/rffi_platform.py:216:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
entries = [<rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcddbb7550>, <rpython.rtyper.tool.rffi_platfo...er object at 0xfffcdc3dd990>, <rpython.rtyper.tool.rffi_platform.DefinedConstantInteger object at 0xfffcdc9dbc50>, ...]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def configure_entries(entries, eci, ignore_errors=False):
writer = _CWriter(eci)
writer.write_header()
for i, entry in enumerate(entries):
writer.write_entry(str(i), entry)
writer.start_main()
for i, entry in enumerate(entries):
writer.write_entry_main(str(i))
writer.close()
infolist = list(run_example_code(
> writer.path, eci, ignore_errors=ignore_errors))
../rpython/rtyper/tool/rffi_platform.py:241:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filepath = local('/tmp/pytest/usession-py3.11-522/platcheck_161.c')
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def run_example_code(filepath, eci, ignore_errors=False):
eci = eci.convert_sources_to_files()
files = [filepath]
> output = build_executable_cache(files, eci, ignore_errors=ignore_errors)
../rpython/rtyper/tool/rffi_platform.py:745:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
c_files = [local('/tmp/pytest/usession-py3.11-522/platcheck_161.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
ignore_errors = False
def build_executable_cache(c_files, eci, ignore_errors=False):
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
_previous = platform.log_errors
try:
if ignore_errors:
platform.log_errors = False
> result = platform.execute(platform.compile(c_files, eci))
../rpython/tool/gcc_cache.py:28:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_161.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
outputfilename = None, standalone = True
def compile(self, cfiles, eci, outputfilename=None, standalone=True):
> ofiles = self._compile_o_files(cfiles, eci, standalone)
../rpython/translator/platform/__init__.py:57:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>
cfiles = [local('/tmp/pytest/usession-py3.11-522/platcheck_161.c')]
eci = <ExternalCompilationInfo (pre_include_bits=(), includes=('sys/types.h', 'sys/s...iles=(), testonly_libraries=(), use_cpp_linker=False, platform=<Linux cc=gcc>)>
standalone = True
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 = <Linux cc=gcc>, cc = 'gcc'
cfile = local('/tmp/pytest/usession-py3.11-522/platcheck_161.c')
compile_args = ['-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', '-Wno-address', ...]
def _compile_c_file(self, cc, cfile, compile_args):
oname = self._make_o_file(cfile, ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
self._execute_c_compiler(cc, args, oname,
> cwd=str(cfile.dirpath()))
../rpython/translator/platform/posix.py:44:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Linux cc=gcc>, cc = 'gcc'
args = ['-c', '-O3', '-pthread', '-fomit-frame-pointer', '-Wall', '-Wno-unused', ...]
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_161.o')
cwd = '/tmp/pytest/usession-py3.11-522'
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 = <Linux cc=gcc>, returncode = 1, stdout = ''
stderr = '/tmp/pytest/usession-py3.11-522/platcheck_161.c: In function \xe2\x80\x98dump_section_447\xe2\x80\x99:\n/tmp/pytest/u...x80\x99}\n 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n | ^~~~~~~~\n'
outname = local('/tmp/pytest/usession-py3.11-522/platcheck_161.o')
def _handle_error(self, returncode, stdout, stderr, outname):
if returncode != 0:
errorfile = outname.new(ext='errors')
errorfile.write(stderr, '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(err="""
E /tmp/pytest/usession-py3.11-522/platcheck_161.c: In function ‘dump_section_447’:
E /tmp/pytest/usession-py3.11-522/platcheck_161.c:6933:18: error: field ‘s’ has incomplete type
E 6933 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_161.c:6936:14: error: storage size of ‘s’ isn’t known
E 6936 | platcheck_t s;
E | ^
E /tmp/pytest/usession-py3.11-522/platcheck_161.c:6939:23: error: invalid application of ‘sizeof’ to incomplete type ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6939 | dump("size", sizeof(platcheck_t));
E | ^~~~~~~~~~~
E In file included from /tmp/pytest/usession-py3.11-522/platcheck_161.c:143:
E /tmp/pytest/usession-py3.11-522/platcheck_161.c:6940:27: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_161.c:6944:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));
E | ^~~~~~~~
E /tmp/pytest/usession-py3.11-522/platcheck_161.c:6948:25: error: invalid use of incomplete typedef ‘platcheck_t’ {aka ‘struct sockaddr_qrtr’}
E 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
E | ^~~~~~~~
E """)
../rpython/translator/platform/__init__.py:155: CompilationError
---------------------------- Captured stderr setup -----------------------------
[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_161.c: In function \u2018dump_section_447\u2019:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_161.c:6933:18: error: field \u2018s\u2019 has incomplete type\n[platform:Error] 6933 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_161.c:6936:14: error: storage size of \u2018s\u2019 isn\u2019t known\n[platform:Error] 6936 | platcheck_t s;\n[platform:Error] | ^\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_161.c:6939:23: error: invalid application of \u2018sizeof\u2019 to incomplete type \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6939 | dump("size", sizeof(platcheck_t));\n[platform:Error] | ^~~~~~~~~~~\n[platform:Error] In file included from /tmp/pytest/usession-py3.11-522/platcheck_161.c:143:\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_161.c:6940:27: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6940 | dump("fldofs sq_family", offsetof(platcheck_t, sq_family));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_161.c:6944:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6944 | dump("fldofs sq_node", offsetof(platcheck_t, sq_node));\n[platform:Error] | ^~~~~~~~\n[platform:Error] /tmp/pytest/usession-py3.11-522/platcheck_161.c:6948:25: error: invalid use of incomplete typedef \u2018platcheck_t\u2019 {aka \u2018struct sockaddr_qrtr\u2019}\n[platform:Error] 6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));\n[platform:Error] | ^~~~~~~~
_____________ ERROR at setup of AppTestBuiltinApp.test_isinstance ______________
self = <CallInfo when='setup' exception: CompilationError(err="""
/tmp/pytest/usession-py3.11-522/platcheck_162.c: In functi...’}
6948 | dump("fldofs sq_port", offsetof(platcheck_t, sq_port));
| ^~~~~~~~
""")>
func = <function <lambda> at 0xfffcdd931d50>, 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_isinstance'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_isinstance'>}
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 0xfffce2ffcf50>
hook = <_HookCaller 'pytest_runtest_setup'>
methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_isinstance'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_isinstance'>}
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 0xfffce183d7d0>, <_pytest.vendored_packages.pluggy.HookImpl in...es.pluggy.HookImpl instance at 0xfffce2583410>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0xfffce25575f0>]
kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_isinstance'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_isinstance'>}
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_isinstance'>, '__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 0xfffcdc253140>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...isinstance'>, '__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 0xfffcdc253820>
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 0xfffcdc253820>
func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...isinstance'>, '__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_isinstance'>, '__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_isinstance'>
@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 = {}, config = <rpython.config.config.Config object at 0xfffcdcd29550>
key = (((True, False, False, True, False, 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 0xfffcdcd29550>
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 0xfffcdcd29550>
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 0xfffcdcd29550>
@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:455:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
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:634:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pypy.module.imp.moduledef.Module object at 0xfffcdc6dfe90>
space = StdObjSpace, args = (W_UnicodeObject('_imp'),)
add_fork_hook = <function add_fork_hook at 0xfffcddfc81d0>
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
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:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
"""
# 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_ALG')
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 a
Output exceeded 6164480 bytes, remaining output has been truncated
program finished with exit code 1
elapsedTime=6917.746140