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 /buildbot/slave/own-linux-x86-64/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=x86_64 AUDITWHEEL_PLAT=manylinux_2_28_x86_64 AUDITWHEEL_POLICY=manylinux_2_28 DEVTOOLSET_ROOTPATH=/opt/rh/gcc-toolset-14/root HGDEMANDIMPORT=disable HOME=/buildbot/slave HOSTNAME=d67408748fba LANG=en_US.UTF-8 LANGUAGE=en_US.UTF-8 LC_ALL=en_US.UTF-8 LD_LIBRARY_PATH=/usr/local/lib:/opt/rh/gcc-toolset-14/root/usr/lib64:/opt/rh/gcc-toolset-14/root/usr/lib:/opt/rh/gcc-toolset-14/root/usr/lib64/dyninst:/opt/rh/gcc-toolset-14/root/usr/lib/dyninst OLDPWD=/buildbot/slave PATH=/tmp/venv/bin:/opt/clang/bin:/opt/rh/gcc-toolset-14/root/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/pypy2.7-v7.3.22-linux64/bin PKG_CONFIG_PATH=/usr/local/lib/pkgconfig PS1=(venv) PWD=/buildbot/slave/own-linux-x86-64/build PYPYCHERRYPICK= PYPY_LOCALBASE=/usr/local PYPY_MAKE_PORTABLE=1 PYTHONPATH=.: SHLVL=0 SSL_CERT_FILE=/opt/_internal/certs.pem TERM=xterm TMPDIR=/tmp/pytest VIRTUAL_ENV=/tmp/venv container=podman using PTY: False using config pypy/testrunner_cfg.py using config /buildbot/slave/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_typedeallocate.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: 144 to run ++ 02:30:12 starting config/test [1 started in total] ++ 02:30:12 starting interpreter/astcompiler/test [2 started in total] ++ 02:30:12 starting interpreter/pyparser/test [3 started in total] ++ 02:30:12 starting interpreter/test [4 started in total] __ config/test [1 done in total, somefailed=False] ____________________________ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.py rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 162 items / 1 skipped config/test/test_pypyoption.py .................................................................................................................................................................. ==================== 162 passed, 1 skipped in 7.50 seconds ===================== ++ 02:30:21 starting module/__builtin__/test [5 started in total] __ interpreter/pyparser/test [2 done in total, somefailed=False] ______________ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 243 items interpreter/pyparser/test/apptest_parsestring.py ...... interpreter/pyparser/test/test_automata.py ... interpreter/pyparser/test/test_future.py ................................... interpreter/pyparser/test/test_gendfa.py .... interpreter/pyparser/test/test_parsestring.py ............ interpreter/pyparser/test/test_pylexer.py . interpreter/pyparser/test/test_pyparse.py ................................................................................................................. interpreter/pyparser/test/test_pytokenizer.py ..................................................................... ========================= 243 passed in 38.74 seconds ========================== ++ 02:30:57 starting module/__pypy__/test [6 started in total] __ module/__builtin__/test [3 done in total, somefailed=False] ________________ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 324 items module/__builtin__/test/apptest_compile.py ..................... module/__builtin__/test/apptest_descriptor.py ....... module/__builtin__/test/apptest_operator.py ..... module/__builtin__/test/apptest_print.py ... module/__builtin__/test/test_abstractinst.py ..........s.. module/__builtin__/test/test_breakpoint.py ........ module/__builtin__/test/test_builtin.py ........................................................................ module/__builtin__/test/test_compile.py .. module/__builtin__/test/test_construct_singletons.py . module/__builtin__/test/test_descriptor.py ................................... module/__builtin__/test/test_dir.py ........... module/__builtin__/test/test_filter.py ........ module/__builtin__/test/test_filter_pickle.py ..... module/__builtin__/test/test_format.py . module/__builtin__/test/test_functional.py ........................................................................................ module/__builtin__/test/test_map_pickle.py ... module/__builtin__/test/test_minmax.py ....................... module/__builtin__/test/test_rawinput.py .. module/__builtin__/test/test_sum.py . module/__builtin__/test/test_vars.py ... module/__builtin__/test/test_zip.py ........... module/__builtin__/test/test_zip_pickle.py . ==================== 323 passed, 1 skipped in 66.90 seconds ==================== ++ 02:31:34 starting module/_abc/test [7 started in total] __ module/__pypy__/test [4 done in total, somefailed=False] ___________________ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 83 items module/__pypy__/test/apptest_picklebuffer.py ........ module/__pypy__/test/test_builders.py ..... module/__pypy__/test/test_bytebuffer.py ... module/__pypy__/test/test_debug.py ....... module/__pypy__/test/test_identitydict.py ...... module/__pypy__/test/test_intop.py ........... module/__pypy__/test/test_locals2fast.py ..... module/__pypy__/test/test_magic.py .......s.. module/__pypy__/test/test_newmemoryview.py ........ module/__pypy__/test/test_os.py . module/__pypy__/test/test_signal.py ..s.s module/__pypy__/test/test_special.py ............s. ==================== 79 passed, 4 skipped in 48.10 seconds ===================== ++ 02:31:48 starting module/_ast/test [8 started in total] __ module/_abc/test [5 done in total, somefailed=False] _______________________ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 6 items module/_abc/test/apptest_abc.py ... module/_abc/test/test_abc.py ... ========================== 6 passed in 18.17 seconds =========================== ++ 02:31:54 starting module/_cffi_backend/test [9 started in total] __ interpreter/astcompiler/test [6 done in total, somefailed=False] ___________ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.py rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 1566 items interpreter/astcompiler/test/apptest_compiler.py .................... interpreter/astcompiler/test/apptest_exceptiongroup.py ......................... interpreter/astcompiler/test/apptest_fstring.py ............................... interpreter/astcompiler/test/apptest_misc.py ................. interpreter/astcompiler/test/apptest_patma.py ......................................... interpreter/astcompiler/test/apptest_walrus_comprehension.py ...... interpreter/astcompiler/test/test_assemble.py ....................... interpreter/astcompiler/test/test_ast.py ............ interpreter/astcompiler/test/test_astbuilder.py ................................................................................................................. interpreter/astcompiler/test/test_compiler.py ......................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................... interpreter/astcompiler/test/test_misc.py ............... interpreter/astcompiler/test/test_symtable.py ................................................. interpreter/astcompiler/test/test_unparse.py ................................ interpreter/astcompiler/test/test_validate.py ..................................................... ======================== 1566 passed in 123.48 seconds ========================= ++ 02:32:23 starting module/_codecs/test [10 started in total] __ module/_ast/test [7 done in total, somefailed=False] _______________________ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 57 items module/_ast/test/apptest_ast.py ... module/_ast/test/test_ast.py ...................................................... ========================== 57 passed in 57.33 seconds ========================== ++ 02:32:46 starting module/_collections/test [11 started in total] __ module/_collections/test [8 done in total, somefailed=False] _______________ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 66 items module/_collections/test/apptest_defaultdict.py .............. module/_collections/test/apptest_deque.py .......................................... module/_collections/test/apptest_ordereddict.py .......... ========================== 66 passed in 41.67 seconds ========================== ++ 02:33:30 starting module/_continuation/test [12 started in total] __ module/_codecs/test [9 done in total, somefailed=False] ____________________ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 99 items module/_codecs/test/apptest_codecs.py .. module/_codecs/test/test_codecs.py .....................sss...........................................................s...... module/_codecs/test/test_locale.py ...ss. module/_codecs/test/test_ztranslation.py . ==================== 93 passed, 6 skipped in 87.69 seconds ===================== ++ 02:33:57 starting module/_cppyy/test [13 started in total] __ module/_cppyy/test [10 done in total, somefailed=False] ____________________ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 0 items ========================= no tests ran in 0.00 seconds ========================= ++ 02:33:59 starting module/_csv/test [14 started in total] __ module/_continuation/test [11 done in total, somefailed=False] _____________ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 72 items / 2 skipped module/_continuation/test/test_generator.py ssss module/_continuation/test/test_greenlet.py s.ssssss.sssssssssssssss.sss module/_continuation/test/test_stacklet.py ssssssssssssssssssssssssssssssssssssssss ==================== 3 passed, 71 skipped in 39.55 seconds ===================== ++ 02:34:15 starting module/_demo/test [15 started in total] __ module/_demo/test [12 done in total, somefailed=False] _____________________ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 3 items module/_demo/test/test_import.py .. module/_demo/test/test_sieve.py . ========================== 3 passed in 14.45 seconds =========================== ++ 02:34:32 starting module/_hpy_universal/test/_vendored [16 started in total] __ module/_hpy_universal/test/_vendored [13 done in total, somefailed=True] ___ INTERNALERROR> Traceback (most recent call last): INTERNALERROR> File "/buildbot/slave/own-linux-x86-64/build/_pytest/main.py", line 109, in wrap_session INTERNALERROR> config.hook.pytest_sessionstart(session=session) INTERNALERROR> File "/buildbot/slave/own-linux-x86-64/build/_pytest/vendored_packages/pluggy.py", line 724, in __call__ INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs) INTERNALERROR> File "/buildbot/slave/own-linux-x86-64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs) INTERNALERROR> File "/buildbot/slave/own-linux-x86-64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda> INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute() INTERNALERROR> File "/buildbot/slave/own-linux-x86-64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute INTERNALERROR> res = hook_impl.function(*args) INTERNALERROR> File "/buildbot/slave/own-linux-x86-64/build/pypy/module/_hpy_universal/test/conftest.py", line 145, in pytest_sessionstart INTERNALERROR> from pypy.module._hpy_universal.test import support as _support INTERNALERROR> File "/buildbot/slave/own-linux-x86-64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module> INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase INTERNALERROR> File "/buildbot/slave/own-linux-x86-64/build/pypy/module/cpyext/test/test_cpyext.py", line 9, in <module> INTERNALERROR> from pypy.module.cpyext import api INTERNALERROR> File "/buildbot/slave/own-linux-x86-64/build/pypy/module/cpyext/api.py", line 29, in <module> INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator INTERNALERROR> File "/buildbot/slave/own-linux-x86-64/build/pypy/interpreter/generator.py", line 3, in <module> INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield INTERNALERROR> File "/buildbot/slave/own-linux-x86-64/build/pypy/interpreter/pyopcode.py", line 15, in <module> INTERNALERROR> from pypy.interpreter import ( INTERNALERROR> File "/buildbot/slave/own-linux-x86-64/build/pypy/interpreter/pyframe.py", line 22, in <module> INTERNALERROR> from pypy.interpreter.pymonitoring import ( INTERNALERROR> File "/buildbot/slave/own-linux-x86-64/build/pypy/interpreter/pymonitoring.py", line 5, in <module> INTERNALERROR> from pypy.interpreter.typedef import TypeDef INTERNALERROR> File "/buildbot/slave/own-linux-x86-64/build/pypy/interpreter/typedef.py", line 572, in <module> INTERNALERROR> from pypy.interpreter.pyframe import PyFrame INTERNALERROR> ImportError: cannot import name 'PyFrame' ++ 02:34:34 starting module/_hpy_universal/test/pypy [17 started in total] __ module/_hpy_universal/test/pypy [14 done in total, somefailed=True] ________ INTERNALERROR> Traceback (most recent call last): INTERNALERROR> File "/buildbot/slave/own-linux-x86-64/build/_pytest/main.py", line 109, in wrap_session INTERNALERROR> config.hook.pytest_sessionstart(session=session) INTERNALERROR> File "/buildbot/slave/own-linux-x86-64/build/_pytest/vendored_packages/pluggy.py", line 724, in __call__ INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs) INTERNALERROR> File "/buildbot/slave/own-linux-x86-64/build/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs) INTERNALERROR> File "/buildbot/slave/own-linux-x86-64/build/_pytest/vendored_packages/pluggy.py", line 333, in <lambda> INTERNALERROR> _MultiCall(methods, kwargs, hook.spec_opts).execute() INTERNALERROR> File "/buildbot/slave/own-linux-x86-64/build/_pytest/vendored_packages/pluggy.py", line 596, in execute INTERNALERROR> res = hook_impl.function(*args) INTERNALERROR> File "/buildbot/slave/own-linux-x86-64/build/pypy/module/_hpy_universal/test/conftest.py", line 145, in pytest_sessionstart INTERNALERROR> from pypy.module._hpy_universal.test import support as _support INTERNALERROR> File "/buildbot/slave/own-linux-x86-64/build/pypy/module/_hpy_universal/test/support.py", line 6, in <module> INTERNALERROR> from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase INTERNALERROR> File "/buildbot/slave/own-linux-x86-64/build/pypy/module/cpyext/test/test_cpyext.py", line 9, in <module> INTERNALERROR> from pypy.module.cpyext import api INTERNALERROR> File "/buildbot/slave/own-linux-x86-64/build/pypy/module/cpyext/api.py", line 29, in <module> INTERNALERROR> from pypy.interpreter.generator import GeneratorIterator INTERNALERROR> File "/buildbot/slave/own-linux-x86-64/build/pypy/interpreter/generator.py", line 3, in <module> INTERNALERROR> from pypy.interpreter.pyopcode import SApplicationException, Yield INTERNALERROR> File "/buildbot/slave/own-linux-x86-64/build/pypy/interpreter/pyopcode.py", line 15, in <module> INTERNALERROR> from pypy.interpreter import ( INTERNALERROR> File "/buildbot/slave/own-linux-x86-64/build/pypy/interpreter/pyframe.py", line 22, in <module> INTERNALERROR> from pypy.interpreter.pymonitoring import ( INTERNALERROR> File "/buildbot/slave/own-linux-x86-64/build/pypy/interpreter/pymonitoring.py", line 5, in <module> INTERNALERROR> from pypy.interpreter.typedef import TypeDef INTERNALERROR> File "/buildbot/slave/own-linux-x86-64/build/pypy/interpreter/typedef.py", line 572, in <module> INTERNALERROR> from pypy.interpreter.pyframe import PyFrame INTERNALERROR> ImportError: cannot import name 'PyFrame' ++ 02:34:35 starting module/_io/test [18 started in total] __ module/_csv/test [15 done in total, somefailed=False] ______________________ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 34 items module/_csv/test/apptest_writer.py ...... module/_csv/test/test_dialect.py .............. module/_csv/test/test_reader.py ............. module/_csv/test/test_ztranslation.py . ========================== 34 passed in 38.33 seconds ========================== ++ 02:34:43 starting module/_jitlog/test [19 started in total] __ module/_jitlog/test [16 done in total, somefailed=False] ___________________ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 1 items module/_jitlog/test/test__jitlog.py . ========================== 1 passed in 11.36 seconds =========================== ++ 02:34:56 starting module/_locale/test [20 started in total] __ module/_locale/test [17 done in total, somefailed=False] ___________________ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 15 items module/_locale/test/test_locale.py sssssssssssssss ========================== 15 skipped in 7.89 seconds ========================== ++ 02:35:06 starting module/_lsprof/test [21 started in total] __ module/_lsprof/test [18 done in total, somefailed=False] ___________________ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 6 items module/_lsprof/test/test_cprofile.py ...... =========================== 6 passed in 9.75 seconds =========================== ++ 02:35:18 starting module/_md5/test [22 started in total] __ module/_md5/test [19 done in total, somefailed=False] ______________________ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 8 items module/_md5/test/test_md5.py ........ =========================== 8 passed in 7.97 seconds =========================== ++ 02:35:28 starting module/_minimal_curses/test [23 started in total] __ module/_minimal_curses/test [20 done in total, somefailed=False] ___________ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 6 items module/_minimal_curses/test/test_curses.py ...... ========================== 6 passed in 62.09 seconds =========================== ++ 02:36:34 starting module/_multibytecodec/test [24 started in total] __ module/_multibytecodec/test [21 done in total, somefailed=False] ___________ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 67 items module/_multibytecodec/test/apptest_codecs.py ................... module/_multibytecodec/test/apptest_incremental.py .................... module/_multibytecodec/test/apptest_stream.py ..... module/_multibytecodec/test/test_c_codecs.py ..................s module/_multibytecodec/test/test_multibtye_codecs.py ... module/_multibytecodec/test/test_translation.py s ==================== 65 passed, 2 skipped in 33.51 seconds ===================== ++ 02:37:12 starting module/_multiprocessing/test [25 started in total] __ module/_io/test [22 done in total, somefailed=False] _______________________ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 287 items / 1 skipped module/_io/test/apptest_bufferedio.py . module/_io/test/apptest_bytesio.py ................. module/_io/test/apptest_io.py ........................................... module/_io/test/apptest_stringio.py ........................... module/_io/test/apptest_textio.py ..............................s.................. module/_io/test/test_bufferedio.py .......................................................................ss................................ module/_io/test/test_fileio.py .................................... module/_io/test/test_interp_textio.py ......... =================== 284 passed, 4 skipped in 167.79 seconds ==================== ++ 02:37:29 starting module/_opcode/test [26 started in total] __ interpreter/test [23 done in total, somefailed=False] ______________________ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc PYTHON3: /usr/local/bin/python3.12 (Version 3.12.13 (main, May 13 2026, 03:55:23) [GCC 14.2.1 20250110 (Red Hat 14.2.1-11)]) rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 1389 items interpreter/test/apptest_annotations.py .......................... interpreter/test/apptest_annotations_string.py ...... interpreter/test/apptest_buffer.py ....... interpreter/test/apptest_class.py ................ interpreter/test/apptest_compiler.py .................................................................................................... interpreter/test/apptest_coroutine.py .......................................................... interpreter/test/apptest_descrtypecheck.py .. interpreter/test/apptest_exceptions.py .......................... interpreter/test/apptest_exctable_dis.py ......... interpreter/test/apptest_exec.py ......................... interpreter/test/apptest_extcall.py ..... interpreter/test/apptest_function.py .....................................s....................................................... interpreter/test/apptest_generator.py ................................................................... interpreter/test/apptest_nestedscope.py .................. interpreter/test/apptest_pep695.py ............................... interpreter/test/apptest_pycode.py .... interpreter/test/apptest_pyframe.py ................................................................ interpreter/test/apptest_raise.py ...................................................... interpreter/test/apptest_settrace_jump.py . interpreter/test/apptest_syntax.py .................................... interpreter/test/apptest_sys_settrace.py .............................................................................................................................................. interpreter/test/apptest_traceback.py ........ interpreter/test/apptest_unraisable.py .... interpreter/test/apptest_with_leak.py ......... interpreter/test/test_app_main.py ..................s..s....................s...s.......................s....x.s...s.......... interpreter/test/test_appinterp.py ............. interpreter/test/test_argument.py ................................................ interpreter/test/test_buffer.py ... interpreter/test/test_cellfamily.py ....... interpreter/test/test_code.py ............ interpreter/test/test_compiler.py ......... interpreter/test/test_error.py .............. interpreter/test/test_exceptcomp.py ......... interpreter/test/test_executioncontext.py ................ interpreter/test/test_extmodules.py . interpreter/test/test_fsencode.py ... interpreter/test/test_function.py ............. interpreter/test/test_gateway.py .........................................ss......................... interpreter/test/test_generator.py . interpreter/test/test_interpreter.py ................................................. interpreter/test/test_location.py .......... interpreter/test/test_main.py ..... interpreter/test/test_mixedmodule.py ...... interpreter/test/test_module.py .................. interpreter/test/test_monitoring.py ....... interpreter/test/test_objspace.py ............................................. interpreter/test/test_pycode.py .. interpreter/test/test_pyframe.py ................................ interpreter/test/test_reverse_debugging.py .. interpreter/test/test_special.py ... interpreter/test/test_syntax.py ..................... interpreter/test/test_targetpypy.py .. interpreter/test/test_typedef.py ................... interpreter/test/test_unicodehelper.py .......... interpreter/test/test_zpy.py ........ interpreter/test/test_zzpickle_and_slow.py s.....s..s..sss........ss...s. ============= 1369 passed, 19 skipped, 1 xfailed in 446.42 seconds ============= ++ 02:37:40 starting module/_pickle/test [27 started in total] __ module/_opcode/test [24 done in total, somefailed=False] ___________________ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 5 items module/_opcode/test/apptest_opcode.py ..... ========================== 5 passed in 11.18 seconds =========================== ++ 02:37:41 starting module/_pickle_support/test [28 started in total] __ module/_pickle_support/test [25 done in total, somefailed=False] ___________ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 1 items module/_pickle_support/test/apptest__pickle_support.py . =========================== 1 passed in 7.82 seconds =========================== ++ 02:37:50 starting module/_posixsubprocess/test [29 started in total] __ module/_multiprocessing/test [26 done in total, somefailed=False] __________ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 13 items module/_multiprocessing/test/test_interp_semaphore.py . module/_multiprocessing/test/test_semaphore.py .......... module/_multiprocessing/test/test_win32.py s module/_multiprocessing/test/test_ztranslation.py . ==================== 12 passed, 1 skipped in 62.06 seconds ===================== ++ 02:38:17 starting module/_pypyjson/test [30 started in total] __ module/_pypyjson/test [27 done in total, somefailed=False] _________________ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 57 items module/_pypyjson/test/apptest__pypyjson.py .......... module/_pypyjson/test/test__pypyjson.py ............................................ module/_pypyjson/test/test_simd.py ... ========================== 57 passed in 38.20 seconds ========================== ++ 02:39:01 starting module/_random/test [31 started in total] __ module/_posixsubprocess/test [28 done in total, somefailed=False] __________ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 10 items module/_posixsubprocess/test/apptest_subprocess.py ......... module/_posixsubprocess/test/test_ztranslation.py . ========================== 10 passed in 71.57 seconds ========================== ++ 02:39:02 starting module/_rawffi/alt/test [32 started in total] __ module/_pickle/test [29 done in total, somefailed=False] ___________________ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 108 items module/_pickle/test/apptest_optional_frames.py .. module/_pickle/test/apptest_pickle.py ..............................................................s................ module/_pickle/test/apptest_pypy_extensions.py ........................... ==================== 107 passed, 1 skipped in 86.50 seconds ==================== ++ 02:39:07 starting module/_rawffi/test [33 started in total] __ module/_rawffi/alt/test [30 done in total, somefailed=False] _______________ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 73 items module/_rawffi/alt/test/test_ffitype.py ..... module/_rawffi/alt/test/test_funcptr.py ..................................ssssss.s module/_rawffi/alt/test/test_struct.py ............... module/_rawffi/alt/test/test_type_converter.py ........... ==================== 66 passed, 7 skipped in 16.26 seconds ===================== ++ 02:39:20 starting module/_socket/test [34 started in total] __ module/_random/test [31 done in total, somefailed=False] ___________________ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 13 items module/_random/test/test_random.py ............ module/_random/test/test_ztranslation.py . ========================== 13 passed in 23.80 seconds ========================== ++ 02:39:29 starting module/_sre/test [35 started in total] __ module/_rawffi/test [32 done in total, somefailed=False] ___________________ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 86 items module/_rawffi/test/apptest_rawffi.py .. module/_rawffi/test/test__rawffi.py ......s.............................................s..........s...... module/_rawffi/test/test_exit.py . module/_rawffi/test/test_nested.py ...... module/_rawffi/test/test_struct.py ... module/_rawffi/test/test_tracker.py ... module/_rawffi/test/test_ztranslation.py . ==================== 83 passed, 3 skipped in 81.08 seconds ===================== n: 2 Arg 0: 3 Arg 1: 15 ++ 02:40:35 starting module/_vmprof/test [36 started in total] __ module/_sre/test [33 done in total, somefailed=False] ______________________ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 163 items module/_sre/test/apptest_sre.py ................................................................................s.s...................... module/_sre/test/test_app_sre.py .............................. module/_sre/test/test_sre_buf.py ............................ ==================== 161 passed, 2 skipped in 73.08 seconds ==================== ++ 02:40:49 starting module/_warnings/test [37 started in total] __ module/_vmprof/test [34 done in total, somefailed=False] ___________________ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 7 items module/_vmprof/test/test__vmprof.py ....s module/_vmprof/test/test_direct.py .. ===================== 6 passed, 1 skipped in 25.45 seconds ===================== ++ 02:41:02 starting module/_weakref/test [38 started in total] __ module/_warnings/test [35 done in total, somefailed=False] _________________ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 22 items module/_warnings/test/apptest_warnings.py ........s.s.......... module/_warnings/test/test_warnings.py . ==================== 20 passed, 2 skipped in 21.47 seconds ===================== ++ 02:41:13 starting module/_winreg/test [39 started in total] __ module/_winreg/test [36 done in total, somefailed=False] ___________________ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 0 items / 1 skipped ========================== 1 skipped in 0.09 seconds =========================== ++ 02:41:14 starting module/array/test [40 started in total] __ module/_socket/test [37 done in total, somefailed=False] ___________________ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 87 items module/_socket/test/apptest_socket.py .....................ss..................s.................... module/_socket/test/test_sock_app.py ........................ module/_socket/test/test_ztranslation.py . ==================== 84 passed, 3 skipped in 119.83 seconds ==================== ++ 02:41:23 starting module/atexit/test [41 started in total] __ module/atexit/test [38 done in total, somefailed=False] ____________________ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 2 items module/atexit/test/apptest_atexit.py .. ========================== 2 passed in 14.07 seconds =========================== ++ 02:41:40 starting module/binascii/test [42 started in total] __ module/_weakref/test [39 done in total, somefailed=False] __________________ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 43 items module/_weakref/test/apptest_weakref.py ........................................... ========================== 43 passed in 41.18 seconds ========================== ++ 02:41:47 starting module/bz2/test [43 started in total] __ module/binascii/test [40 done in total, somefailed=False] __________________ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 18 items module/binascii/test/test_binascii.py .................. ========================== 18 passed in 16.85 seconds ========================== ++ 02:42:00 starting module/cmath/test [44 started in total] __ module/cmath/test [41 done in total, somefailed=False] _____________________ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 18 items module/cmath/test/test_cmath.py .................. ========================== 18 passed in 9.90 seconds =========================== ++ 02:42:13 starting module/cpyext/test/test_api.py [45 started in total] __ module/_cffi_backend/test [42 done in total, somefailed=True] ______________ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 468 items module/_cffi_backend/test/test_c.py ....................................................................................s....................................................s.....s.......................s.............................s........................s...... module/_cffi_backend/test/test_fastpath.py .................. module/_cffi_backend/test/test_ffi_obj.py ............................................... module/_cffi_backend/test/test_file.py s.. module/_cffi_backend/test/test_parse_c_type.py ..............s... module/_cffi_backend/test/test_re_python.py .................... module/_cffi_backend/test/test_recompiler.py EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE module/_cffi_backend/test/test_unicode_literals.py ....... module/_cffi_backend/test/test_wchar_helper.py . module/_cffi_backend/test/test_ztranslation.py s ==================================== ERRORS ==================================== ______________ ERROR at setup of AppTestRecompiler.test_math_sin _______________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x00000000187c4bd8>, 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_math_sin'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_math_sin'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_math_sin'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_math_sin'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_math_sin'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_math_sin'>} 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_math_sin'>, '__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 0x000000001893a160> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_math_sin'>, '__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 0x0000000009b6e320> 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 0x0000000009b6e320> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_math_sin'>, '__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_math_sin'>, '__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_math_sin'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x00000000164a9ef8> key = (((True, True, True, 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 0x00000000164a9ef8> 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 0x00000000164a9ef8> 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 0x00000000164a9ef8> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000008f9f520> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000198210f8> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x00000000084bbb78>, <W_TypeObject 'GenericAlias' at 0x1acf9ec0>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b360368> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b360368> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b360368> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b360368> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1312abc0>> w_obj = <W_TypeObject 'ellipsis' at 0x1b360368> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x1b360368>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1312abc0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x1b360368> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1312abc0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1312abc0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1312abc0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ______________ ERROR at setup of AppTestRecompiler.test_repr_lib _______________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000001cf456a0>, 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_repr_lib'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_repr_lib'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_repr_lib'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_repr_lib'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_repr_lib'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_repr_lib'>} 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_repr_lib'>, '__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 0x000000001d957880> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_repr_lib'>, '__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 0x000000001d915160> 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 0x000000001d915160> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_repr_lib'>, '__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_repr_lib'>, '__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_repr_lib'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000001d99c6b0> key = (((True, True, True, 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 0x000000001d99c6b0> 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 0x000000001d99c6b0> 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 0x000000001d99c6b0> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000001e0fc060> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000001e1e3a98> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000001d99cc28>, <W_TypeObject 'GenericAlias' at 0x1ea360c8>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1eab5360> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1eab5360> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1eab5360> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1eab5360> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1eb0c780>> w_obj = <W_TypeObject 'ellipsis' at 0x1eab5360> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x1eab5360>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1eb0c780>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x1eab5360> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1eb0c780>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1eb0c780>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1eb0c780>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _____________ ERROR at setup of AppTestRecompiler.test_funcarg_ptr _____________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x00000000201ccc50>, 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_funcarg_ptr'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_funcarg_ptr'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_funcarg_ptr'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_funcarg_ptr'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_funcarg_ptr'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_funcarg_ptr'>} 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_funcarg_ptr'>, '__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 0x0000000020c79128> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...uncarg_ptr'>, '__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 0x0000000020c76aa0> 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 0x0000000020c76aa0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...uncarg_ptr'>, '__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_funcarg_ptr'>, '__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_funcarg_ptr'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000020c61a28> key = (((True, True, True, 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 0x0000000020c61a28> 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 0x0000000020c61a28> 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 0x0000000020c61a28> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000020eb2a60> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000020f6bfa0> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000020c61fa0>, <W_TypeObject 'GenericAlias' at 0x218210c0>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x219602c0> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x219602c0> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x219602c0> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x219602c0> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x219bbd80>> w_obj = <W_TypeObject 'ellipsis' at 0x219602c0> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x219602c0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x219bbd80>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x219602c0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x219bbd80>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x219bbd80>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x219bbd80>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _____________ ERROR at setup of AppTestRecompiler.test_funcres_ptr _____________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x00000000231c1f88>, 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_funcres_ptr'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_funcres_ptr'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_funcres_ptr'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_funcres_ptr'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_funcres_ptr'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_funcres_ptr'>} 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_funcres_ptr'>, '__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 0x0000000023dd57e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...uncres_ptr'>, '__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 0x0000000023dd0420> 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 0x0000000023dd0420> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...uncres_ptr'>, '__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_funcres_ptr'>, '__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_funcres_ptr'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000023dca9f8> key = (((True, True, True, 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 0x0000000023dca9f8> 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 0x0000000023dca9f8> 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 0x0000000023dca9f8> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000024285ba0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000024398c28> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000023dcaf70>, <W_TypeObject 'GenericAlias' at 0x24938410>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x24b0d050> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x24b0d050> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x24b0d050> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x24b0d050> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x24b7f1f0>> w_obj = <W_TypeObject 'ellipsis' at 0x24b0d050> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x24b0d050>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x24b7f1f0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x24b0d050> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x24b7f1f0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x24b7f1f0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x24b7f1f0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError __________ ERROR at setup of AppTestRecompiler.test_global_var_array ___________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x00000000187c56a0>, 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_global_var_array'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_global_var_array'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_global_var_array'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_global_var_array'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_global_var_array'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_global_var_array'>} 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_global_var_array'>, '__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 0x00000000187aa7c8> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._var_array'>, '__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 0x00000000104d46a0> 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 0x00000000104d46a0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._var_array'>, '__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_global_var_array'>, '__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_global_var_array'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000018eb79f0> key = (((True, True, True, 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 0x0000000018eb79f0> 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 0x0000000018eb79f0> 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 0x0000000018eb79f0> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x00000000150e09e0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000019241248> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000018eb7f68>, <W_TypeObject 'GenericAlias' at 0x19e1acd0>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1a007cc8> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1a007cc8> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1a007cc8> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1a007cc8> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1baa4590>> w_obj = <W_TypeObject 'ellipsis' at 0x1a007cc8> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x1a007cc8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1baa4590>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x1a007cc8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1baa4590>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1baa4590>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1baa4590>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ___________ ERROR at setup of AppTestRecompiler.test_verify_typedef ____________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000019aeff88>, 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_verify_typedef'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_verify_typedef'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_verify_typedef'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_verify_typedef'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_verify_typedef'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_verify_typedef'>} 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_verify_typedef'>, '__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 0x00000000169a76c8> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...fy_typedef'>, '__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 0x000000000d0111a0> 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 0x000000000d0111a0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...fy_typedef'>, '__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_verify_typedef'>, '__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_verify_typedef'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000018fe2138> key = (((True, True, True, 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 0x0000000018fe2138> 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 0x0000000018fe2138> 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 0x0000000018fe2138> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000001456ad60> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000024e05600> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000018fe26b0>, <W_TypeObject 'GenericAlias' at 0x18fa3948>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21675718> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21675718> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21675718> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21675718> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x24a6c510>> w_obj = <W_TypeObject 'ellipsis' at 0x21675718> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x21675718>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x24a6c510>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x21675718> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x24a6c510>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x24a6c510>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x24a6c510>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ______ ERROR at setup of AppTestRecompiler.test_verify_typedef_dotdotdot _______ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000001e252548>, 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_verify_typedef_dotdotdot'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_verify_typedef_dotdotdot'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_verify_typedef_dotdotdot'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_verify_typedef_dotdotdot'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_verify_typedef_dotdotdot'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_verify_typedef_dotdotdot'>} 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_verify_typedef_dotdotdot'>, '__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 0x000000001a7cecc8> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._dotdotdot'>, '__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 0x0000000021d6c820> 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 0x0000000021d6c820> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._dotdotdot'>, '__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_verify_typedef_dotdotdot'>, '__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_verify_typedef_dotdotdot'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000002102bad0> key = (((True, True, True, 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 0x000000002102bad0> 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 0x000000002102bad0> 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 0x000000002102bad0> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000002330a9a0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000002321c020> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000024fe6090>, <W_TypeObject 'GenericAlias' at 0x22a4b670>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x22a72e58> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x22a72e58> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x22a72e58> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x22a72e58> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x256f2520>> w_obj = <W_TypeObject 'ellipsis' at 0x22a72e58> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x22a72e58>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x256f2520>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x22a72e58> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x256f2520>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x256f2520>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x256f2520>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ____ ERROR at setup of AppTestRecompiler.test_verify_typedef_star_dotdotdot ____ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000023dd8a70>, 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_verify_typedef_star_dotdotdot'>...call__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_verify_typedef_star_dotdotdot'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_verify_typedef_star_dotdotdot'>...call__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_verify_typedef_star_dotdotdot'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_verify_typedef_star_dotdotdot'>...call__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_verify_typedef_star_dotdotdot'>} 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_verify_typedef_star_dotdotdot'>, '__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 0x000000001e1bfec0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._dotdotdot'>, '__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 0x0000000021abdaa0> 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 0x0000000021abdaa0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._dotdotdot'>, '__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_verify_typedef_star_dotdotdot'>, '__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_verify_typedef_star_dotdotdot'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000021a93b78> key = (((True, True, True, 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 0x0000000021a93b78> 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 0x0000000021a93b78> 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 0x0000000021a93b78> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000001fe778e0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000001c212368> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000021a43210>, <W_TypeObject 'GenericAlias' at 0x22fa3d00>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x202e35c8> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x202e35c8> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x202e35c8> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x202e35c8> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x215d70a0>> w_obj = <W_TypeObject 'ellipsis' at 0x202e35c8> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x202e35c8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x215d70a0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x202e35c8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x215d70a0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x215d70a0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x215d70a0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ___________ ERROR at setup of AppTestRecompiler.test_global_var_int ____________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000023b0c4d0>, 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_global_var_int'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_global_var_int'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_global_var_int'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_global_var_int'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_global_var_int'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_global_var_int'>} 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_global_var_int'>, '__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 0x0000000023f710d8> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...al_var_int'>, '__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 0x0000000022bf84a0> 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 0x0000000022bf84a0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...al_var_int'>, '__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_global_var_int'>, '__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_global_var_int'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000001f33d868> key = (((True, True, True, 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 0x000000001f33d868> 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 0x000000001f33d868> 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 0x000000001f33d868> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000022ce1ea0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000023627670> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000001f33dde0>, <W_TypeObject 'GenericAlias' at 0x1bd8b830>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1be4b520> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1be4b520> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1be4b520> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1be4b520> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x24659450>> w_obj = <W_TypeObject 'ellipsis' at 0x1be4b520> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x1be4b520>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x24659450>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x1be4b520> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x24659450>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x24659450>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x24659450>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ________________ ERROR at setup of AppTestRecompiler.test_macro ________________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000026a4e728>, 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_macro'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_macro'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_macro'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_macro'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_macro'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_macro'>} 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_macro'>, '__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 0x000000002736a020> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...test_macro'>, '__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 0x0000000027308460> 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 0x0000000027308460> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...test_macro'>, '__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_macro'>, '__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_macro'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x00000000272f7018> key = (((True, True, True, 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 0x00000000272f7018> 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 0x00000000272f7018> 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 0x00000000272f7018> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x00000000273d34e0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000274a04b8> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x00000000272f7590>, <W_TypeObject 'GenericAlias' at 0x2775f1d8>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x277b4c98> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x277b4c98> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x277b4c98> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x277b4c98> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21097120>> w_obj = <W_TypeObject 'ellipsis' at 0x277b4c98> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x277b4c98>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21097120>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x277b4c98> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21097120>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21097120>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21097120>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError __________ ERROR at setup of AppTestRecompiler.test_macro_check_value __________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000028d699e8>, 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_macro_check_value'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_macro_check_value'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_macro_check_value'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_macro_check_value'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_macro_check_value'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_macro_check_value'>} 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_macro_check_value'>, '__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 0x00000000298c0ac0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...heck_value'>, '__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 0x0000000029897860> 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 0x0000000029897860> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...heck_value'>, '__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_macro_check_value'>, '__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_macro_check_value'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000002989fe18> key = (((True, True, True, 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 0x000000002989fe18> 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 0x000000002989fe18> 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 0x000000002989fe18> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000029a7a0a0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000029ae2170> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000029918678>, <W_TypeObject 'GenericAlias' at 0x17c9e560>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x17c5b520> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x17c5b520> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x17c5b520> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x17c5b520> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x23552e90>> w_obj = <W_TypeObject 'ellipsis' at 0x17c5b520> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x17c5b520>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x23552e90>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x17c5b520> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x23552e90>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x23552e90>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x23552e90>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ______________ ERROR at setup of AppTestRecompiler.test_constant _______________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x00000000114789f8>, 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_constant'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_constant'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_constant'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_constant'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_constant'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_constant'>} 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_constant'>, '__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 0x0000000017507808> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_constant'>, '__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 0x0000000005da7a60> 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 0x0000000005da7a60> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_constant'>, '__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_constant'>, '__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_constant'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000001e955b40> key = (((True, True, True, 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 0x000000001e955b40> 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 0x000000001e955b40> 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 0x000000001e955b40> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x00000000028210e0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000020d348e0> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000001e97a100>, <W_TypeObject 'GenericAlias' at 0x24b17868>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x19015478> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x19015478> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x19015478> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x19015478> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x22a12f90>> w_obj = <W_TypeObject 'ellipsis' at 0x19015478> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x19015478>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x22a12f90>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x19015478> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x22a12f90>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x22a12f90>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x22a12f90>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _____ ERROR at setup of AppTestRecompiler.test_check_value_of_static_const _____ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000019733088>, 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_check_value_of_static_const'>, ...ticall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_check_value_of_static_const'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_check_value_of_static_const'>, ...ticall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_check_value_of_static_const'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_check_value_of_static_const'>, ...ticall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_check_value_of_static_const'>} 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_check_value_of_static_const'>, '__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 0x0000000016bcf678> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...atic_const'>, '__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 0x000000001c48f2a0> 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 0x000000001c48f2a0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...atic_const'>, '__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_check_value_of_static_const'>, '__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_check_value_of_static_const'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x00000000201f0c28> key = (((True, True, True, 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 0x00000000201f0c28> 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 0x00000000201f0c28> 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 0x00000000201f0c28> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000001cceb7a0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000024033b08> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x00000000201f1440>, <W_TypeObject 'GenericAlias' at 0x1b57bc58>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b5694e8> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b5694e8> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b5694e8> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b5694e8> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1df8a520>> w_obj = <W_TypeObject 'ellipsis' at 0x1b5694e8> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x1b5694e8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1df8a520>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x1b5694e8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1df8a520>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1df8a520>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1df8a520>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ___________ ERROR at setup of AppTestRecompiler.test_constant_nonint ___________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000001ae6ad40>, 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_constant_nonint'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_constant_nonint'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_constant_nonint'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_constant_nonint'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_constant_nonint'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_constant_nonint'>} 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_constant_nonint'>, '__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 0x000000001a556b38> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ant_nonint'>, '__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 0x0000000022cabb20> 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 0x0000000022cabb20> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ant_nonint'>, '__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_constant_nonint'>, '__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_constant_nonint'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000019694250> key = (((True, True, True, 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 0x0000000019694250> 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 0x0000000019694250> 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 0x0000000019694250> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000023684f60> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000192ea090> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x00000000196947c8>, <W_TypeObject 'GenericAlias' at 0x2316caa0>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x220e3248> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x220e3248> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x220e3248> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x220e3248> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x248ae1a0>> w_obj = <W_TypeObject 'ellipsis' at 0x220e3248> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x220e3248>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x248ae1a0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x220e3248> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x248ae1a0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x248ae1a0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x248ae1a0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ____________ ERROR at setup of AppTestRecompiler.test_constant_ptr _____________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x00000000201cc6b0>, 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_constant_ptr'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_constant_ptr'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_constant_ptr'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_constant_ptr'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_constant_ptr'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_constant_ptr'>} 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_constant_ptr'>, '__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 0x000000001ba40c00> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...nstant_ptr'>, '__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 0x000000001cbd9920> 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 0x000000001cbd9920> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...nstant_ptr'>, '__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_constant_ptr'>, '__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_constant_ptr'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000001cbf5980> key = (((True, True, True, 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 0x000000001cbf5980> 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 0x000000001cbf5980> 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 0x000000001cbf5980> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000021f308e0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000021eefe50> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x00000000212501e0>, <W_TypeObject 'GenericAlias' at 0x25b21ec0>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x207af4e8> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x207af4e8> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x207af4e8> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x207af4e8> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1f784b60>> w_obj = <W_TypeObject 'ellipsis' at 0x207af4e8> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x207af4e8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1f784b60>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x207af4e8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1f784b60>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1f784b60>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1f784b60>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _________________ ERROR at setup of AppTestRecompiler.test_dir _________________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000024613cb8>, 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] 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 0x000000001ffbd8f8> 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 0x00000000272075e0> 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 0x00000000272075e0> 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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000002724ecd0> key = (((True, True, True, 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 0x000000002724ecd0> 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 0x000000002724ecd0> 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 0x000000002724ecd0> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000025e656e0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000026b2e528> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000002724f248>, <W_TypeObject 'GenericAlias' at 0x23960de8>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x25cda2c0> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x25cda2c0> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x25cda2c0> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x25cda2c0> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1063cf10>> w_obj = <W_TypeObject 'ellipsis' at 0x25cda2c0> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x25cda2c0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1063cf10>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x25cda2c0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1063cf10>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1063cf10>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1063cf10>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ________ ERROR at setup of AppTestRecompiler.test_verify_opaque_struct _________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000023606b60>, 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_verify_opaque_struct'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_verify_opaque_struct'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_verify_opaque_struct'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_verify_opaque_struct'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_verify_opaque_struct'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_verify_opaque_struct'>} 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_verify_opaque_struct'>, '__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 0x00000000249f7a38> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...que_struct'>, '__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 0x0000000025f661a0> 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 0x0000000025f661a0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...que_struct'>, '__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_verify_opaque_struct'>, '__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_verify_opaque_struct'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000025f07750> key = (((True, True, True, 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 0x0000000025f07750> 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 0x0000000025f07750> 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 0x0000000025f07750> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000002705f3a0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000270b2bf0> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000025f07cc8>, <W_TypeObject 'GenericAlias' at 0x28561520>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x285a7670> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x285a7670> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x285a7670> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x285a7670> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xe98a730>> w_obj = <W_TypeObject 'ellipsis' at 0x285a7670> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x285a7670>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xe98a730>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x285a7670> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xe98a730>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xe98a730>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xe98a730>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _________ ERROR at setup of AppTestRecompiler.test_verify_opaque_union _________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x00000000299336a0>, 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_verify_opaque_union'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_verify_opaque_union'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_verify_opaque_union'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_verify_opaque_union'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_verify_opaque_union'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_verify_opaque_union'>} 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_verify_opaque_union'>, '__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 0x000000001893aac0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...aque_union'>, '__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 0x000000000f0bcc20> 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 0x000000000f0bcc20> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...aque_union'>, '__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_verify_opaque_union'>, '__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_verify_opaque_union'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x00000000174b0090> key = (((True, True, True, 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 0x00000000174b0090> 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 0x00000000174b0090> 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 0x00000000174b0090> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000000f0af860> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000016f20a68> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x00000000174b0608>, <W_TypeObject 'GenericAlias' at 0x190276a8>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x191dc218> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x191dc218> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x191dc218> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x191dc218> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xb379f90>> w_obj = <W_TypeObject 'ellipsis' at 0x191dc218> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x191dc218>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xb379f90>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x191dc218> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xb379f90>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xb379f90>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xb379f90>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ____________ ERROR at setup of AppTestRecompiler.test_verify_struct ____________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000024f66c50>, 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_verify_struct'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_verify_struct'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_verify_struct'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_verify_struct'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_verify_struct'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_verify_struct'>} 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_verify_struct'>, '__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 0x00000000167a6a48> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ify_struct'>, '__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 0x00000000127a59e0> 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 0x00000000127a59e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ify_struct'>, '__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_verify_struct'>, '__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_verify_struct'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000017a4dc90> key = (((True, True, True, 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 0x0000000017a4dc90> 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 0x0000000017a4dc90> 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 0x0000000017a4dc90> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000012820be0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000019d4e528> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000017a5a250>, <W_TypeObject 'GenericAlias' at 0x1c213520>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1f3eae20> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1f3eae20> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1f3eae20> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1f3eae20> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x116e3490>> w_obj = <W_TypeObject 'ellipsis' at 0x1f3eae20> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x1f3eae20>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x116e3490>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x1f3eae20> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x116e3490>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x116e3490>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x116e3490>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ______ ERROR at setup of AppTestRecompiler.test_verify_exact_field_offset ______ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000019783880>, 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_verify_exact_field_offset'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_verify_exact_field_offset'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_verify_exact_field_offset'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_verify_exact_field_offset'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_verify_exact_field_offset'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_verify_exact_field_offset'>} 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_verify_exact_field_offset'>, '__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 0x0000000016c44480> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...eld_offset'>, '__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 0x000000001edebda0> 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 0x000000001edebda0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...eld_offset'>, '__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_verify_exact_field_offset'>, '__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_verify_exact_field_offset'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000002481d168> key = (((True, True, True, 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 0x000000002481d168> 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 0x000000002481d168> 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 0x000000002481d168> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000001edfb1e0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000027371360> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000002481d6e0>, <W_TypeObject 'GenericAlias' at 0x1a79e2f8>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2840a2f8> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2840a2f8> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2840a2f8> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2840a2f8> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21ed1d70>> w_obj = <W_TypeObject 'ellipsis' at 0x2840a2f8> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x2840a2f8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21ed1d70>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x2840a2f8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21ed1d70>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21ed1d70>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21ed1d70>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ____________ ERROR at setup of AppTestRecompiler.test_type_caching _____________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000001cf45e98>, 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_caching'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_type_caching'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_type_caching'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_type_caching'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_type_caching'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_type_caching'>} 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_caching'>, '__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 0x000000001a147a60> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...pe_caching'>, '__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 0x000000002125bae0> 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 0x000000002125bae0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...pe_caching'>, '__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_caching'>, '__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_caching'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x00000000228db830> key = (((True, True, True, 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 0x00000000228db830> 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 0x00000000228db830> 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 0x00000000228db830> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000001bca6760> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000002124c950> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x00000000228dbda8>, <W_TypeObject 'GenericAlias' at 0x27446560>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x27442410> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x27442410> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x27442410> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x27442410> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1349f9b0>> w_obj = <W_TypeObject 'ellipsis' at 0x27442410> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x27442410>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1349f9b0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x27442410> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1349f9b0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1349f9b0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1349f9b0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _____________ ERROR at setup of AppTestRecompiler.test_verify_enum _____________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000021de2188>, 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_verify_enum'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_verify_enum'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_verify_enum'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_verify_enum'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_verify_enum'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_verify_enum'>} 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_verify_enum'>, '__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 0x000000001b64f7b8> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...erify_enum'>, '__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 0x00000000238414e0> 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 0x00000000238414e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...erify_enum'>, '__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_verify_enum'>, '__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_verify_enum'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x00000000245677c0> key = (((True, True, True, 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 0x00000000245677c0> 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 0x00000000245677c0> 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 0x00000000245677c0> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000023844a60> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000001ca63558> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000024567d38>, <W_TypeObject 'GenericAlias' at 0x2987dad0>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x298ecbf0> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x298ecbf0> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x298ecbf0> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x298ecbf0> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2a65e60>> w_obj = <W_TypeObject 'ellipsis' at 0x298ecbf0> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x298ecbf0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2a65e60>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x298ecbf0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2a65e60>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2a65e60>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2a65e60>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ___ ERROR at setup of AppTestRecompiler.test_dotdotdot_length_of_array_field ___ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000001c1ade20>, 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_dotdotdot_length_of_array_field...ll__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_dotdotdot_length_of_array_field'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_dotdotdot_length_of_array_field...ll__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_dotdotdot_length_of_array_field'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_dotdotdot_length_of_array_field...ll__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_dotdotdot_length_of_array_field'>} 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_dotdotdot_length_of_array_field'>, '__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 0x000000001e7d52b8> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...rray_field'>, '__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 0x0000000026c1dae0> 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 0x0000000026c1dae0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...rray_field'>, '__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_dotdotdot_length_of_array_field'>, '__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_dotdotdot_length_of_array_field'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000026c4f8a0> key = (((True, True, True, 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 0x0000000026c4f8a0> 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 0x0000000026c4f8a0> 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 0x0000000026c4f8a0> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000021aaf020> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000002242ef00> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000026c4fe18>, <W_TypeObject 'GenericAlias' at 0x28e18f00>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x28e68870> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x28e68870> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x28e68870> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x28e68870> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x488cf70>> w_obj = <W_TypeObject 'ellipsis' at 0x28e68870> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x28e68870>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x488cf70>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x28e68870> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x488cf70>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x488cf70>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x488cf70>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _______ ERROR at setup of AppTestRecompiler.test_dotdotdot_global_array ________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000002636b268>, 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_dotdotdot_global_array'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_dotdotdot_global_array'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_dotdotdot_global_array'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_dotdotdot_global_array'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_dotdotdot_global_array'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_dotdotdot_global_array'>} 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_dotdotdot_global_array'>, '__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 0x000000002326e188> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...obal_array'>, '__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 0x000000001fde35e0> 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 0x000000001fde35e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...obal_array'>, '__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_dotdotdot_global_array'>, '__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_dotdotdot_global_array'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000001fddd948> key = (((True, True, True, 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 0x000000001fddd948> 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 0x000000001fddd948> 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 0x000000001fddd948> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000001d83c760> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000001f593de0> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000001fdddec0>, <W_TypeObject 'GenericAlias' at 0x28a05168>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x28a31600> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x28a31600> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x28a31600> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x28a31600> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1bb5f9d0>> w_obj = <W_TypeObject 'ellipsis' at 0x28a31600> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x28a31600>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1bb5f9d0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x28a31600> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1bb5f9d0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1bb5f9d0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1bb5f9d0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _________ ERROR at setup of AppTestRecompiler.test_misdeclared_field_1 _________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000002a34f628>, 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_misdeclared_field_1'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_misdeclared_field_1'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_misdeclared_field_1'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_misdeclared_field_1'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_misdeclared_field_1'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_misdeclared_field_1'>} 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_misdeclared_field_1'>, '__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 0x000000002add8570> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ed_field_1'>, '__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 0x000000002ad6dc20> 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 0x000000002ad6dc20> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ed_field_1'>, '__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_misdeclared_field_1'>, '__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_misdeclared_field_1'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000002ad7b670> key = (((True, True, True, 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 0x000000002ad7b670> 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 0x000000002ad7b670> 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 0x000000002ad7b670> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000002ae06d20> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000002af066b0> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000002ad7bbe8>, <W_TypeObject 'GenericAlias' at 0x29991f30>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1c2970f8> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1c2970f8> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1c2970f8> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1c2970f8> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7428c70>> w_obj = <W_TypeObject 'ellipsis' at 0x1c2970f8> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x1c2970f8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7428c70>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x1c2970f8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7428c70>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7428c70>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7428c70>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ________ ERROR at setup of AppTestRecompiler.test_open_array_in_struct _________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000029ab4e30>, 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_open_array_in_struct'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_open_array_in_struct'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_open_array_in_struct'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_open_array_in_struct'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_open_array_in_struct'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_open_array_in_struct'>} 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_open_array_in_struct'>, '__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 0x0000000017017b78> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._in_struct'>, '__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 0x0000000008e695e0> 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 0x0000000008e695e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._in_struct'>, '__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_open_array_in_struct'>, '__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_open_array_in_struct'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000001ad45050> key = (((True, True, True, 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 0x000000001ad45050> 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 0x000000001ad45050> 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 0x000000001ad45050> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000008c93820> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000001b7c1c58> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000001ad87a60>, <W_TypeObject 'GenericAlias' at 0x1f8e8b48>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2016f868> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2016f868> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2016f868> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2016f868> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1348ae60>> w_obj = <W_TypeObject 'ellipsis' at 0x2016f868> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x2016f868>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1348ae60>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x2016f868> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1348ae60>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1348ae60>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1348ae60>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ____________ ERROR at setup of AppTestRecompiler.test_math_sin_type ____________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000018924020>, 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_math_sin_type'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_math_sin_type'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_math_sin_type'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_math_sin_type'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_math_sin_type'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_math_sin_type'>} 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_math_sin_type'>, '__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 0x00000000168fb060> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...h_sin_type'>, '__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 0x000000001b39df60> 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 0x000000001b39df60> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...h_sin_type'>, '__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_math_sin_type'>, '__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_math_sin_type'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000025f7ee20> key = (((True, True, True, 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 0x0000000025f7ee20> 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 0x0000000025f7ee20> 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 0x0000000025f7ee20> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000001b495ae0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000026ed2c28> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000025f7f718>, <W_TypeObject 'GenericAlias' at 0x28e1e870>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x25277478> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x25277478> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x25277478> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x25277478> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1dd1ed80>> w_obj = <W_TypeObject 'ellipsis' at 0x25277478> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x25277478>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1dd1ed80>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x25277478> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1dd1ed80>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1dd1ed80>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1dd1ed80>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ERROR at setup of AppTestRecompiler.test_verify_anonymous_struct_with_typedef _ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000019f6c110>, 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_verify_anonymous_struct_with_ty...: <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_verify_anonymous_struct_with_typedef'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_verify_anonymous_struct_with_ty...: <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_verify_anonymous_struct_with_typedef'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_verify_anonymous_struct_with_ty...: <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_verify_anonymous_struct_with_typedef'>} 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_verify_anonymous_struct_with_typedef'>, '__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 0x0000000019b45b00> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...th_typedef'>, '__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 0x0000000021a497e0> 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 0x0000000021a497e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...th_typedef'>, '__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_verify_anonymous_struct_with_typedef'>, '__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_verify_anonymous_struct_with_typedef'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000001de70560> key = (((True, True, True, 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 0x000000001de70560> 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 0x000000001de70560> 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 0x000000001de70560> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000001fe1cb60> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000019d2d9f0> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000001de70ad8>, <W_TypeObject 'GenericAlias' at 0x1e763830>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1c303050> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1c303050> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1c303050> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1c303050> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x865a300>> w_obj = <W_TypeObject 'ellipsis' at 0x1c303050> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x1c303050>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x865a300>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x1c303050> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x865a300>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x865a300>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x865a300>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ERROR at setup of AppTestRecompiler.test_verify_anonymous_struct_with_star_typedef self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000001e261f10>, 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_verify_anonymous_struct_with_st...ultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_verify_anonymous_struct_with_star_typedef'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_verify_anonymous_struct_with_st...ultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_verify_anonymous_struct_with_star_typedef'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_verify_anonymous_struct_with_st...ultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_verify_anonymous_struct_with_star_typedef'>} 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_verify_anonymous_struct_with_star_typedef'>, '__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 0x000000001aaac278> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ar_typedef'>, '__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 0x0000000026980a20> 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 0x0000000026980a20> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ar_typedef'>, '__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_verify_anonymous_struct_with_star_typedef'>, '__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_verify_anonymous_struct_with_star_typedef'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000024ff2d78> key = (((True, True, True, 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 0x0000000024ff2d78> 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 0x0000000024ff2d78> 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 0x0000000024ff2d78> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000028edf720> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000001f812100> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000024ff32f0>, <W_TypeObject 'GenericAlias' at 0x1d5ba288>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x25a7c330> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x25a7c330> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x25a7c330> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x25a7c330> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10c65640>> w_obj = <W_TypeObject 'ellipsis' at 0x25a7c330> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x25a7c330>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10c65640>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x25a7c330> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10c65640>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10c65640>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10c65640>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _ ERROR at setup of AppTestRecompiler.test_verify_anonymous_enum_with_typedef __ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000024394ea8>, 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_verify_anonymous_enum_with_type..._': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_verify_anonymous_enum_with_typedef'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_verify_anonymous_enum_with_type..._': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_verify_anonymous_enum_with_typedef'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_verify_anonymous_enum_with_type..._': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_verify_anonymous_enum_with_typedef'>} 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_verify_anonymous_enum_with_typedef'>, '__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 0x000000001cd70c28> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...th_typedef'>, '__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 0x000000002645c1a0> 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 0x000000002645c1a0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...th_typedef'>, '__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_verify_anonymous_enum_with_typedef'>, '__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_verify_anonymous_enum_with_typedef'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000002645ac98> key = (((True, True, True, 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 0x000000002645ac98> 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 0x000000002645ac98> 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 0x000000002645ac98> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000002645d520> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000020793b08> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000002645b210>, <W_TypeObject 'GenericAlias' at 0x26320bf0>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x262f6cd0> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x262f6cd0> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x262f6cd0> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x262f6cd0> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1bb638f0>> w_obj = <W_TypeObject 'ellipsis' at 0x262f6cd0> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x262f6cd0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1bb638f0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x262f6cd0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1bb638f0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1bb638f0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1bb638f0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ____________ ERROR at setup of AppTestRecompiler.test_unique_types _____________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000002362f808>, 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_unique_types'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_unique_types'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_unique_types'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_unique_types'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_unique_types'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_unique_types'>} 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_unique_types'>, '__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 0x0000000020d17ba0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ique_types'>, '__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 0x0000000029cfe020> 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 0x0000000029cfe020> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ique_types'>, '__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_unique_types'>, '__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_unique_types'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000029d600c8> key = (((True, True, True, 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 0x0000000029d600c8> 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 0x0000000029d600c8> 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 0x0000000029d600c8> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000029bf0960> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000029c222c0> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000029d60640>, <W_TypeObject 'GenericAlias' at 0x1f5f1168>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1f62d830> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1f62d830> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1f62d830> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1f62d830> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x14bb55f0>> w_obj = <W_TypeObject 'ellipsis' at 0x1f62d830> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x1f62d830>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x14bb55f0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x1f62d830> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x14bb55f0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x14bb55f0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x14bb55f0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _______ ERROR at setup of AppTestRecompiler.test_module_name_in_package ________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000001f5ac200>, 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_module_name_in_package'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_module_name_in_package'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_module_name_in_package'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_module_name_in_package'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_module_name_in_package'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_module_name_in_package'>} 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_module_name_in_package'>, '__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 0x0000000024b0ee58> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...in_package'>, '__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 0x00000000265fc3e0> 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 0x00000000265fc3e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...in_package'>, '__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_module_name_in_package'>, '__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_module_name_in_package'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x00000000265f2c98> key = (((True, True, True, 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 0x00000000265f2c98> 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 0x00000000265f2c98> 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 0x00000000265f2c98> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x00000000265fd4e0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000027fdc1e0> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x00000000265f3210>, <W_TypeObject 'GenericAlias' at 0x2af21cc8>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x18d39f68> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x18d39f68> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x18d39f68> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x18d39f68> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xb3c26a0>> w_obj = <W_TypeObject 'ellipsis' at 0x18d39f68> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x18d39f68>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xb3c26a0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x18d39f68> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xb3c26a0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xb3c26a0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xb3c26a0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ____ ERROR at setup of AppTestRecompiler.test_unspecified_size_of_global_1 _____ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000002af17d30>, 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_unspecified_size_of_global_1'>,...icall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_unspecified_size_of_global_1'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_unspecified_size_of_global_1'>,...icall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_unspecified_size_of_global_1'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_unspecified_size_of_global_1'>,...icall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_unspecified_size_of_global_1'>} 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_unspecified_size_of_global_1'>, '__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 0x0000000029983e98> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...f_global_1'>, '__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 0x00000000098990a0> 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 0x00000000098990a0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...f_global_1'>, '__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_unspecified_size_of_global_1'>, '__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_unspecified_size_of_global_1'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000001a9b54b0> key = (((True, True, True, 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 0x000000001a9b54b0> 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 0x000000001a9b54b0> 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 0x000000001a9b54b0> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000009878f20> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000001abfe1a8> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000001a9b5a60>, <W_TypeObject 'GenericAlias' at 0x1e290288>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e3e8f70> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e3e8f70> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e3e8f70> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e3e8f70> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xeaf7cd0>> w_obj = <W_TypeObject 'ellipsis' at 0x1e3e8f70> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x1e3e8f70>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xeaf7cd0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x1e3e8f70> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xeaf7cd0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xeaf7cd0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xeaf7cd0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ____ ERROR at setup of AppTestRecompiler.test_unspecified_size_of_global_2 _____ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000024f671f0>, 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_unspecified_size_of_global_2'>,...icall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_unspecified_size_of_global_2'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_unspecified_size_of_global_2'>,...icall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_unspecified_size_of_global_2'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_unspecified_size_of_global_2'>,...icall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_unspecified_size_of_global_2'>} 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_unspecified_size_of_global_2'>, '__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 0x000000001758c8e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...f_global_2'>, '__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 0x000000001adc6420> 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 0x000000001adc6420> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...f_global_2'>, '__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_unspecified_size_of_global_2'>, '__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_unspecified_size_of_global_2'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000021f3bad0> key = (((True, True, True, 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 0x0000000021f3bad0> 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 0x0000000021f3bad0> 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 0x0000000021f3bad0> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000001adde5e0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000228e3f30> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000021f50090>, <W_TypeObject 'GenericAlias' at 0x21227948>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x27420d40> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x27420d40> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x27420d40> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x27420d40> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e1f8890>> w_obj = <W_TypeObject 'ellipsis' at 0x27420d40> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x27420d40>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e1f8890>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x27420d40> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e1f8890>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e1f8890>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e1f8890>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ____ ERROR at setup of AppTestRecompiler.test_unspecified_size_of_global_3 _____ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000019aeec50>, 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_unspecified_size_of_global_3'>,...icall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_unspecified_size_of_global_3'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_unspecified_size_of_global_3'>,...icall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_unspecified_size_of_global_3'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_unspecified_size_of_global_3'>,...icall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_unspecified_size_of_global_3'>} 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_unspecified_size_of_global_3'>, '__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 0x00000000164ce408> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...f_global_3'>, '__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 0x0000000020566420> 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 0x0000000020566420> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...f_global_3'>, '__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_unspecified_size_of_global_3'>, '__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_unspecified_size_of_global_3'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000022608218> key = (((True, True, True, 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 0x0000000022608218> 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 0x0000000022608218> 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 0x0000000022608218> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000001f7919a0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000220c4330> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000022608790>, <W_TypeObject 'GenericAlias' at 0x28416838>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1ea93ad0> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1ea93ad0> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1ea93ad0> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1ea93ad0> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21081970>> w_obj = <W_TypeObject 'ellipsis' at 0x1ea93ad0> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x1ea93ad0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21081970>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x1ea93ad0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21081970>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21081970>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x21081970>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ____ ERROR at setup of AppTestRecompiler.test_unspecified_size_of_global_4 _____ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000001e957cb8>, 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_unspecified_size_of_global_4'>,...icall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_unspecified_size_of_global_4'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_unspecified_size_of_global_4'>,...icall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_unspecified_size_of_global_4'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_unspecified_size_of_global_4'>,...icall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_unspecified_size_of_global_4'>} 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_unspecified_size_of_global_4'>, '__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 0x0000000019d8d6f0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...f_global_4'>, '__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 0x000000002697bae0> 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 0x000000002697bae0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...f_global_4'>, '__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_unspecified_size_of_global_4'>, '__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_unspecified_size_of_global_4'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000001c053050> key = (((True, True, True, 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 0x000000001c053050> 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 0x000000001c053050> 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 0x000000001c053050> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x00000000269dcf60> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000001ec56218> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x00000000263df0f8>, <W_TypeObject 'GenericAlias' at 0x19a39280>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x285d3d38> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x285d3d38> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x285d3d38> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x285d3d38> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1dc63fc0>> w_obj = <W_TypeObject 'ellipsis' at 0x285d3d38> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x285d3d38>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1dc63fc0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x285d3d38> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1dc63fc0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1dc63fc0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1dc63fc0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ______________ ERROR at setup of AppTestRecompiler.test_include_1 ______________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000025b00e30>, 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_include_1'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_include_1'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_include_1'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_include_1'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_include_1'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_include_1'>} 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_include_1'>, '__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 0x000000001ac76390> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._include_1'>, '__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 0x000000001971b5e0> 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 0x000000001971b5e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._include_1'>, '__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_include_1'>, '__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_include_1'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x00000000196f7c20> key = (((True, True, True, 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 0x00000000196f7c20> 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 0x00000000196f7c20> 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 0x00000000196f7c20> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x00000000234da260> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000001ef923d8> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000028d2c1e0>, <W_TypeObject 'GenericAlias' at 0x1fa50410>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1cadac60> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1cadac60> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1cadac60> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1cadac60> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1339f540>> w_obj = <W_TypeObject 'ellipsis' at 0x1cadac60> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x1cadac60>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1339f540>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x1cadac60> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1339f540>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1339f540>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1339f540>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _____________ ERROR at setup of AppTestRecompiler.test_include_1b ______________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000026a4f3d0>, 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_include_1b'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_include_1b'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_include_1b'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_include_1b'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_include_1b'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_include_1b'>} 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_include_1b'>, '__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 0x000000001dc1a548> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...include_1b'>, '__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 0x000000001bfb62e0> 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 0x000000001bfb62e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...include_1b'>, '__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_include_1b'>, '__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_include_1b'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000001bffccd0> key = (((True, True, True, 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 0x000000001bffccd0> 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 0x000000001bffccd0> 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 0x000000001bffccd0> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000001bfb7c20> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000001bb9f328> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000001bffd248>, <W_TypeObject 'GenericAlias' at 0x278806e8>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x278c1d38> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x278c1d38> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x278c1d38> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x278c1d38> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f16090>> w_obj = <W_TypeObject 'ellipsis' at 0x278c1d38> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x278c1d38>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f16090>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x278c1d38> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f16090>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f16090>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f16090>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ______________ ERROR at setup of AppTestRecompiler.test_include_2 ______________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000002952c980>, 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_include_2'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_include_2'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_include_2'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_include_2'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_include_2'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_include_2'>} 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_include_2'>, '__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 0x000000002148c2c8> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._include_2'>, '__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 0x00000000275c1660> 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 0x00000000275c1660> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._include_2'>, '__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_include_2'>, '__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_include_2'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x00000000275bd360> key = (((True, True, True, 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 0x00000000275bd360> 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 0x00000000275bd360> 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 0x00000000275bd360> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000026cba760> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000027a310f8> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x00000000275bd8d8>, <W_TypeObject 'GenericAlias' at 0x297e90c0>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x297eb6e0> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x297eb6e0> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x297eb6e0> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x297eb6e0> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x138d7d80>> w_obj = <W_TypeObject 'ellipsis' at 0x297eb6e0> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x297eb6e0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x138d7d80>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x297eb6e0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x138d7d80>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x138d7d80>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x138d7d80>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ______________ ERROR at setup of AppTestRecompiler.test_include_3 ______________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000025123880>, 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_include_3'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_include_3'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_include_3'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_include_3'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_include_3'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_include_3'>} 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_include_3'>, '__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 0x0000000023d1c480> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._include_3'>, '__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 0x00000000097608e0> 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 0x00000000097608e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._include_3'>, '__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_include_3'>, '__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_include_3'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000001a1cc608> key = (((True, True, True, 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 0x000000001a1cc608> 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 0x000000001a1cc608> 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 0x000000001a1cc608> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000009a0f260> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000001a5e1018> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000001a1cd050>, <W_TypeObject 'GenericAlias' at 0x1b7ceb48>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b978608> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b978608> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b978608> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1b978608> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107df5b0>> w_obj = <W_TypeObject 'ellipsis' at 0x1b978608> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x1b978608>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107df5b0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x1b978608> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107df5b0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107df5b0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107df5b0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ______________ ERROR at setup of AppTestRecompiler.test_include_4 ______________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000018968890>, 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_include_4'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_include_4'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_include_4'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_include_4'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_include_4'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_include_4'>} 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_include_4'>, '__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 0x0000000025a51920> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._include_4'>, '__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 0x0000000010279ea0> 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 0x0000000010279ea0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._include_4'>, '__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_include_4'>, '__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_include_4'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000001a3ca2f8> key = (((True, True, True, 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 0x000000001a3ca2f8> 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 0x000000001a3ca2f8> 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 0x000000001a3ca2f8> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000000fa875e0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000001fbc7c58> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000001a3ca9f8>, <W_TypeObject 'GenericAlias' at 0x1fd63fa0>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21d34368> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21d34368> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21d34368> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21d34368> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xfde9290>> w_obj = <W_TypeObject 'ellipsis' at 0x21d34368> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x21d34368>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xfde9290>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x21d34368> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xfde9290>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xfde9290>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xfde9290>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ______________ ERROR at setup of AppTestRecompiler.test_include_5 ______________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x00000000197d2458>, 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_include_5'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_include_5'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_include_5'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_include_5'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_include_5'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_include_5'>} 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_include_5'>, '__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 0x000000001753dd30> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._include_5'>, '__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 0x0000000024f5eda0> 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 0x0000000024f5eda0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._include_5'>, '__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_include_5'>, '__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_include_5'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000027ac68e0> key = (((True, True, True, 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 0x0000000027ac68e0> 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 0x0000000027ac68e0> 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 0x0000000027ac68e0> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000002509a060> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000001f3f5130> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000027ac6e58>, <W_TypeObject 'GenericAlias' at 0x1a454cd0>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1a45c640> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1a45c640> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1a45c640> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1a45c640> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11cef810>> w_obj = <W_TypeObject 'ellipsis' at 0x1a45c640> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x1a45c640>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11cef810>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x1a45c640> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11cef810>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11cef810>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11cef810>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ______________ ERROR at setup of AppTestRecompiler.test_include_6 ______________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000001e261790>, 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_include_6'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_include_6'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_include_6'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_include_6'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_include_6'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_include_6'>} 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_include_6'>, '__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 0x00000000163f4458> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._include_6'>, '__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 0x00000000221f6420> 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 0x00000000221f6420> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._include_6'>, '__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_include_6'>, '__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_include_6'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000001a82e678> key = (((True, True, True, 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 0x000000001a82e678> 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 0x000000001a82e678> 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 0x000000001a82e678> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x00000000221f7620> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000002a14b7f8> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000001a82ebf0>, <W_TypeObject 'GenericAlias' at 0x1ca423d8>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d012410> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d012410> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d012410> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1d012410> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1db5f820>> w_obj = <W_TypeObject 'ellipsis' at 0x1d012410> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x1d012410>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1db5f820>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x1d012410> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1db5f820>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1db5f820>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1db5f820>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ______________ ERROR at setup of AppTestRecompiler.test_include_7 ______________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000001c978020>, 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_include_7'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_include_7'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_include_7'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_include_7'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_include_7'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_include_7'>} 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_include_7'>, '__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 0x0000000019c54e30> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._include_7'>, '__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 0x00000000196d1ba0> 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 0x00000000196d1ba0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._include_7'>, '__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_include_7'>, '__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_include_7'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x00000000197039f0> key = (((True, True, True, 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 0x00000000197039f0> 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 0x00000000197039f0> 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 0x00000000197039f0> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x00000000247b4ce0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000021a9c368> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000019703f68>, <W_TypeObject 'GenericAlias' at 0x25bb9e88>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x25b72de8> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x25b72de8> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x25b72de8> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x25b72de8> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xf28f5b0>> w_obj = <W_TypeObject 'ellipsis' at 0x25b72de8> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x25b72de8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xf28f5b0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x25b72de8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xf28f5b0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xf28f5b0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xf28f5b0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ______________ ERROR at setup of AppTestRecompiler.test_include_8 ______________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x00000000274938f8>, 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_include_8'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_include_8'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_include_8'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_include_8'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_include_8'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_include_8'>} 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_include_8'>, '__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 0x000000001ab266b0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._include_8'>, '__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 0x000000001c1970a0> 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 0x000000001c1970a0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._include_8'>, '__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_include_8'>, '__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_include_8'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000001c15d718> key = (((True, True, True, 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 0x000000001c15d718> 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 0x000000001c15d718> 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 0x000000001c15d718> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000026bff0e0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000001d1994b0> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000026c6af00>, <W_TypeObject 'GenericAlias' at 0x204cafe0>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2aebe800> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2aebe800> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2aebe800> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2aebe800> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x217c1ef0>> w_obj = <W_TypeObject 'ellipsis' at 0x2aebe800> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x2aebe800>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x217c1ef0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x2aebe800> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x217c1ef0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x217c1ef0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x217c1ef0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ___________ ERROR at setup of AppTestRecompiler.test_bitfield_basic ____________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000024d55f10>, 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_bitfield_basic'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_bitfield_basic'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_bitfield_basic'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_bitfield_basic'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_bitfield_basic'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_bitfield_basic'>} 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_bitfield_basic'>, '__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 0x000000001cfe9e48> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ield_basic'>, '__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 0x000000002871f0a0> 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 0x000000002871f0a0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ield_basic'>, '__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_bitfield_basic'>, '__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_bitfield_basic'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000028760aa0> key = (((True, True, True, 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 0x0000000028760aa0> 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 0x0000000028760aa0> 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 0x0000000028760aa0> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x00000000295a0260> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000028ff94b0> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000028761018>, <W_TypeObject 'GenericAlias' at 0x25ee9c58>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x25edd408> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x25edd408> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x25edd408> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x25edd408> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1ecb0700>> w_obj = <W_TypeObject 'ellipsis' at 0x25edd408> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x25edd408>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1ecb0700>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x25edd408> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1ecb0700>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1ecb0700>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1ecb0700>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ______ ERROR at setup of AppTestRecompiler.test_incomplete_struct_as_arg _______ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x00000000281b6548>, 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_incomplete_struct_as_arg'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_incomplete_struct_as_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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_incomplete_struct_as_arg'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_incomplete_struct_as_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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_incomplete_struct_as_arg'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_incomplete_struct_as_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_incomplete_struct_as_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 0x0000000021164db8> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...uct_as_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 0x000000002b575020> 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 0x000000002b575020> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...uct_as_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_incomplete_struct_as_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_incomplete_struct_as_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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000002b513e88> key = (((True, True, True, 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 0x000000002b513e88> 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 0x000000002b513e88> 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 0x000000002b513e88> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000028c2c320> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000238d48e0> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...10>, <pypy.interpreter.special.Ellipsis object at 0x000000002b58c448>, <W_TypeObject 'GenericAlias' at 0x84b72f0>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x81c6528> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x81c6528> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x81c6528> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x81c6528> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x251c1f10>> w_obj = <W_TypeObject 'ellipsis' at 0x81c6528> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x81c6528>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x251c1f10>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x81c6528> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x251c1f10>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x251c1f10>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x251c1f10>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _____ ERROR at setup of AppTestRecompiler.test_incomplete_struct_as_result _____ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x00000000124651f0>, 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_incomplete_struct_as_result'>, ...ticall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_incomplete_struct_as_result'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_incomplete_struct_as_result'>, ...ticall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_incomplete_struct_as_result'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_incomplete_struct_as_result'>, ...ticall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_incomplete_struct_as_result'>} 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_incomplete_struct_as_result'>, '__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 0x00000000229d4818> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._as_result'>, '__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 0x0000000008401920> 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 0x0000000008401920> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._as_result'>, '__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_incomplete_struct_as_result'>, '__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_incomplete_struct_as_result'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000001cd68790> key = (((True, True, True, 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 0x000000001cd68790> 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 0x000000001cd68790> 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 0x000000001cd68790> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000000660f720> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000001dfb49f8> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000001cd697c0>, <W_TypeObject 'GenericAlias' at 0x2154e480>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2170fe18> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2170fe18> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2170fe18> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2170fe18> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11b75a60>> w_obj = <W_TypeObject 'ellipsis' at 0x2170fe18> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x2170fe18>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11b75a60>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x2170fe18> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11b75a60>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11b75a60>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11b75a60>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ______ ERROR at setup of AppTestRecompiler.test_incomplete_struct_as_both ______ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x00000000194f6cc8>, 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_incomplete_struct_as_both'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_incomplete_struct_as_both'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_incomplete_struct_as_both'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_incomplete_struct_as_both'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_incomplete_struct_as_both'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_incomplete_struct_as_both'>} 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_incomplete_struct_as_both'>, '__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 0x000000000b4d7650> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ct_as_both'>, '__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 0x000000001b57ec20> 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 0x000000001b57ec20> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ct_as_both'>, '__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_incomplete_struct_as_both'>, '__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_incomplete_struct_as_both'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000002364ff68> key = (((True, True, True, 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 0x000000002364ff68> 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 0x000000002364ff68> 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 0x000000002364ff68> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000001b598760> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000002259b0f8> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000027374528>, <W_TypeObject 'GenericAlias' at 0x25169558>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2a3102c0> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2a3102c0> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2a3102c0> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2a3102c0> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10254d80>> w_obj = <W_TypeObject 'ellipsis' at 0x2a3102c0> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x2a3102c0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10254d80>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x2a3102c0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10254d80>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10254d80>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10254d80>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _______ ERROR at setup of AppTestRecompiler.test_name_of_unnamed_struct ________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000001e141358>, 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_name_of_unnamed_struct'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_name_of_unnamed_struct'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_name_of_unnamed_struct'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_name_of_unnamed_struct'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_name_of_unnamed_struct'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_name_of_unnamed_struct'>} 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_name_of_unnamed_struct'>, '__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 0x000000001783cc78> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...med_struct'>, '__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 0x00000000239dcfe0> 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 0x00000000239dcfe0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...med_struct'>, '__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_name_of_unnamed_struct'>, '__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_name_of_unnamed_struct'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000021f30fa8> key = (((True, True, True, 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 0x0000000021f30fa8> 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 0x0000000021f30fa8> 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 0x0000000021f30fa8> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x00000000239f80e0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000215aa3a0> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000021f31520>, <W_TypeObject 'GenericAlias' at 0x27096de8>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x27bcbef8> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x27bcbef8> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x27bcbef8> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x27bcbef8> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20cd03f0>> w_obj = <W_TypeObject 'ellipsis' at 0x27bcbef8> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x27bcbef8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20cd03f0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x27bcbef8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20cd03f0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20cd03f0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20cd03f0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ________ ERROR at setup of AppTestRecompiler.test_address_of_global_var ________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000025b00a70>, 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_address_of_global_var'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_address_of_global_var'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_address_of_global_var'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_address_of_global_var'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_address_of_global_var'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_address_of_global_var'>} 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_address_of_global_var'>, '__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 0x0000000015a172b8> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...global_var'>, '__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 0x000000001c079920> 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 0x000000001c079920> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...global_var'>, '__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_address_of_global_var'>, '__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_address_of_global_var'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000025315b78> key = (((True, True, True, 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 0x0000000025315b78> 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 0x0000000025315b78> 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 0x0000000025315b78> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x00000000252dd620> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000017a36e90> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000001a530138>, <W_TypeObject 'GenericAlias' at 0x1aa2cb10>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1aa2ba28> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1aa2ba28> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1aa2ba28> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1aa2ba28> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1ff9c6e0>> w_obj = <W_TypeObject 'ellipsis' at 0x1aa2ba28> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x1aa2ba28>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1ff9c6e0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x1aa2ba28> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1ff9c6e0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1ff9c6e0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1ff9c6e0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ___________ ERROR at setup of AppTestRecompiler.test_defines__CFFI_ ____________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000027493a60>, 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_defines__CFFI_'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_defines__CFFI_'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_defines__CFFI_'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_defines__CFFI_'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_defines__CFFI_'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_defines__CFFI_'>} 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_defines__CFFI_'>, '__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 0x0000000019dd88b8> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...nes__CFFI_'>, '__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 0x000000001d3bf6e0> 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 0x000000001d3bf6e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...nes__CFFI_'>, '__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_defines__CFFI_'>, '__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_defines__CFFI_'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000002679b088> key = (((True, True, True, 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 0x000000002679b088> 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 0x000000002679b088> 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 0x000000002679b088> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000001d3fb120> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000001b6b8c98> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000002679b600>, <W_TypeObject 'GenericAlias' at 0x2541d0c0>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x262fbbb0> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x262fbbb0> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x262fbbb0> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x262fbbb0> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1191ca60>> w_obj = <W_TypeObject 'ellipsis' at 0x262fbbb0> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x262fbbb0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1191ca60>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x262fbbb0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1191ca60>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1191ca60>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1191ca60>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _____________ ERROR at setup of AppTestRecompiler.test_unpack_args _____________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000002952cae8>, 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_unpack_args'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_unpack_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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_unpack_args'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_unpack_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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_unpack_args'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_unpack_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_unpack_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 0x000000001ace8980> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...npack_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 0x00000000283c7da0> 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 0x00000000283c7da0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...npack_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_unpack_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_unpack_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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000028375408> key = (((True, True, True, 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 0x0000000028375408> 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 0x0000000028375408> 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 0x0000000028375408> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000002972eee0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000028963d38> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000028375980>, <W_TypeObject 'GenericAlias' at 0x24bf6598>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x28b9fc58> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x28b9fc58> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x28b9fc58> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x28b9fc58> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2106ae00>> w_obj = <W_TypeObject 'ellipsis' at 0x28b9fc58> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x28b9fc58>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2106ae00>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x28b9fc58> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2106ae00>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2106ae00>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2106ae00>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _________ ERROR at setup of AppTestRecompiler.test_address_of_function _________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000002275e7a0>, 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_address_of_function'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_address_of_function'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_address_of_function'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_address_of_function'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_address_of_function'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_address_of_function'>} 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_address_of_function'>, '__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 0x000000001dfd4548> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...f_function'>, '__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 0x00000000203f9b20> 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 0x00000000203f9b20> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...f_function'>, '__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_address_of_function'>, '__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_address_of_function'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000002040cde8> key = (((True, True, True, 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 0x000000002040cde8> 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 0x000000002040cde8> 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 0x000000002040cde8> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x00000000275e4ba0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000021bde4b8> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000002040d360>, <W_TypeObject 'GenericAlias' at 0x22aa2368>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x22ac4560> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x22ac4560> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x22ac4560> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x22ac4560> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e15080>> w_obj = <W_TypeObject 'ellipsis' at 0x22ac4560> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x22ac4560>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e15080>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x22ac4560> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e15080>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e15080>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e15080>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ___ ERROR at setup of AppTestRecompiler.test_address_of_function_with_struct ___ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x00000000281b6188>, 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_address_of_function_with_struct...ll__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_address_of_function_with_struct'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_address_of_function_with_struct...ll__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_address_of_function_with_struct'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_address_of_function_with_struct...ll__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_address_of_function_with_struct'>} 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_address_of_function_with_struct'>, '__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 0x00000000214decc8> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ith_struct'>, '__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 0x000000001001a760> 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 0x000000001001a760> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ith_struct'>, '__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_address_of_function_with_struct'>, '__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_address_of_function_with_struct'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000017b52db0> key = (((True, True, True, 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 0x0000000017b52db0> 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 0x0000000017b52db0> 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 0x0000000017b52db0> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000001001be20> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000001778e720> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000017b538a0>, <W_TypeObject 'GenericAlias' at 0x18ede1e0>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x18f26918> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x18f26918> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x18f26918> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x18f26918> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x242d8c10>> w_obj = <W_TypeObject 'ellipsis' at 0x18f26918> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x18f26918>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x242d8c10>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x18f26918> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x242d8c10>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x242d8c10>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x242d8c10>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ______________ ERROR at setup of AppTestRecompiler.test_issue198 _______________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000000fd6bad8>, 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_issue198'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_issue198'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_issue198'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_issue198'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_issue198'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_issue198'>} 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_issue198'>, '__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 0x000000002add85e8> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_issue198'>, '__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 0x000000000d1d5020> 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 0x000000000d1d5020> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_issue198'>, '__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_issue198'>, '__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_issue198'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000024869e18> key = (((True, True, True, 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 0x0000000024869e18> 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 0x0000000024869e18> 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 0x0000000024869e18> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000001247c120> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000018e4b558> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x00000000248fc3d8>, <W_TypeObject 'GenericAlias' at 0x234ccad8>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x25203e50> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x25203e50> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x25203e50> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x25203e50> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x23fc44e0>> w_obj = <W_TypeObject 'ellipsis' at 0x25203e50> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x25203e50>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x23fc44e0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x25203e50> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x23fc44e0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x23fc44e0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x23fc44e0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _ ERROR at setup of AppTestRecompiler.test_constant_is_not_a_compiler_constant _ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000019782bd8>, 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_constant_is_not_a_compiler_cons...': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_constant_is_not_a_compiler_constant'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_constant_is_not_a_compiler_cons...': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_constant_is_not_a_compiler_constant'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_constant_is_not_a_compiler_cons...': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_constant_is_not_a_compiler_constant'>} 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_constant_is_not_a_compiler_constant'>, '__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 0x0000000018b0f920> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...r_constant'>, '__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 0x000000001e17cc60> 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 0x000000001e17cc60> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...r_constant'>, '__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_constant_is_not_a_compiler_constant'>, '__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_constant_is_not_a_compiler_constant'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000017e78fa8> key = (((True, True, True, 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 0x0000000017e78fa8> 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 0x0000000017e78fa8> 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 0x0000000017e78fa8> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000001e1ab060> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000001ff33478> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000017e79830>, <W_TypeObject 'GenericAlias' at 0x1ec7ead8>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x199cf670> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x199cf670> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x199cf670> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x199cf670> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x242da020>> w_obj = <W_TypeObject 'ellipsis' at 0x199cf670> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x199cf670>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x242da020>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x199cf670> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x242da020>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x242da020>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x242da020>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ______ ERROR at setup of AppTestRecompiler.test_constant_of_unknown_size _______ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000001f98ec50>, 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_constant_of_unknown_size'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_constant_of_unknown_size'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_constant_of_unknown_size'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_constant_of_unknown_size'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_constant_of_unknown_size'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_constant_of_unknown_size'>} 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_constant_of_unknown_size'>, '__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 0x00000000176d65e8> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...known_size'>, '__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 0x00000000279278a0> 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 0x00000000279278a0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...known_size'>, '__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_constant_of_unknown_size'>, '__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_constant_of_unknown_size'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000021210058> key = (((True, True, True, 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 0x0000000021210058> 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 0x0000000021210058> 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 0x0000000021210058> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000002799f520> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000024c00aa0> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x00000000212105d0>, <W_TypeObject 'GenericAlias' at 0x1dbee800>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x27d29750> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x27d29750> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x27d29750> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x27d29750> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x14b94d50>> w_obj = <W_TypeObject 'ellipsis' at 0x27d29750> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x27d29750>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x14b94d50>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x27d29750> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x14b94d50>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x14b94d50>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x14b94d50>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ______ ERROR at setup of AppTestRecompiler.test_variable_of_unknown_size _______ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000022f9e908>, 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_variable_of_unknown_size'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_variable_of_unknown_size'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_variable_of_unknown_size'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_variable_of_unknown_size'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_variable_of_unknown_size'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_variable_of_unknown_size'>} 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_variable_of_unknown_size'>, '__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 0x00000000151f1dd0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...known_size'>, '__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 0x0000000021e5baa0> 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 0x0000000021e5baa0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...known_size'>, '__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_variable_of_unknown_size'>, '__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_variable_of_unknown_size'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x00000000281d8c60> key = (((True, True, True, 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 0x00000000281d8c60> 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 0x00000000281d8c60> 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 0x00000000281d8c60> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000002632cf20> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000262ef408> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x00000000281d91d8>, <W_TypeObject 'GenericAlias' at 0x22023718>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2204f7f8> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2204f7f8> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2204f7f8> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2204f7f8> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x142b8200>> w_obj = <W_TypeObject 'ellipsis' at 0x2204f7f8> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x2204f7f8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x142b8200>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x2204f7f8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x142b8200>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x142b8200>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x142b8200>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ERROR at setup of AppTestRecompiler.test_constant_of_value_unknown_to_the_compiler self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000001d8aa548>, 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_constant_of_value_unknown_to_th...ultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_constant_of_value_unknown_to_the_compiler'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_constant_of_value_unknown_to_th...ultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_constant_of_value_unknown_to_the_compiler'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_constant_of_value_unknown_to_th...ultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_constant_of_value_unknown_to_the_compiler'>} 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_constant_of_value_unknown_to_the_compiler'>, '__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 0x0000000019e7c070> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...e_compiler'>, '__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 0x0000000027db6320> 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 0x0000000027db6320> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...e_compiler'>, '__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_constant_of_value_unknown_to_the_compiler'>, '__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_constant_of_value_unknown_to_the_compiler'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000001ff4fb40> key = (((True, True, True, 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 0x000000001ff4fb40> 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 0x000000001ff4fb40> 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 0x000000001ff4fb40> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000027db7e60> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000001fa32330> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000002a53e100>, <W_TypeObject 'GenericAlias' at 0x22cc9018>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x28149590> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x28149590> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x28149590> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x28149590> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20fe1820>> w_obj = <W_TypeObject 'ellipsis' at 0x28149590> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x28149590>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20fe1820>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x28149590> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20fe1820>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20fe1820>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20fe1820>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ____ ERROR at setup of AppTestRecompiler.test_call_with_incomplete_structs _____ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000025e9d8f8>, 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_call_with_incomplete_structs'>,...icall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_call_with_incomplete_structs'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_call_with_incomplete_structs'>,...icall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_call_with_incomplete_structs'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_call_with_incomplete_structs'>,...icall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_call_with_incomplete_structs'>} 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_call_with_incomplete_structs'>, '__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 0x000000001ae13e70> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...te_structs'>, '__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 0x000000002a0ce2e0> 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 0x000000002a0ce2e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...te_structs'>, '__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_call_with_incomplete_structs'>, '__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_call_with_incomplete_structs'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000002a0c57c0> key = (((True, True, True, 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 0x000000002a0c57c0> 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 0x000000002a0c57c0> 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 0x000000002a0c57c0> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000002a0cf720> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000027220bb8> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000002a0c5d38>, <W_TypeObject 'GenericAlias' at 0x1f3638d8>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1f39a950> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1f39a950> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1f39a950> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1f39a950> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e9131c0>> w_obj = <W_TypeObject 'ellipsis' at 0x1f39a950> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x1f39a950>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e9131c0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x1f39a950> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e9131c0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e9131c0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e9131c0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _____ ERROR at setup of AppTestRecompiler.test_struct_array_guess_length_2 _____ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000002a3b7da8>, 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_struct_array_guess_length_2'>, ...ticall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_struct_array_guess_length_2'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_struct_array_guess_length_2'>, ...ticall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_struct_array_guess_length_2'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_struct_array_guess_length_2'>, ...ticall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_struct_array_guess_length_2'>} 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_struct_array_guess_length_2'>, '__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 0x000000001dd774e8> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...s_length_2'>, '__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 0x0000000029b3f160> 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 0x0000000029b3f160> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...s_length_2'>, '__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_struct_array_guess_length_2'>, '__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_struct_array_guess_length_2'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000029af3f68> key = (((True, True, True, 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 0x0000000029af3f68> 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 0x0000000029af3f68> 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 0x0000000029af3f68> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000001d35a960> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000001f463638> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000002a192528>, <W_TypeObject 'GenericAlias' at 0x2b1e9e18>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2804e218> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2804e218> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2804e218> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2804e218> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xac62200>> w_obj = <W_TypeObject 'ellipsis' at 0x2804e218> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x2804e218>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xac62200>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x2804e218> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xac62200>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xac62200>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xac62200>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _____ ERROR at setup of AppTestRecompiler.test_struct_array_guess_length_3 _____ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000002c175ad8>, 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_struct_array_guess_length_3'>, ...ticall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_struct_array_guess_length_3'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_struct_array_guess_length_3'>, ...ticall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_struct_array_guess_length_3'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_struct_array_guess_length_3'>, ...ticall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_struct_array_guess_length_3'>} 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_struct_array_guess_length_3'>, '__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 0x0000000021703e98> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...s_length_3'>, '__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 0x00000000100ecae0> 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 0x00000000100ecae0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...s_length_3'>, '__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_struct_array_guess_length_3'>, '__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_struct_array_guess_length_3'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000017ba5fa0> key = (((True, True, True, 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 0x0000000017ba5fa0> 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 0x0000000017ba5fa0> 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 0x0000000017ba5fa0> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000010295a60> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000001749afa8> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000017ba2aa0>, <W_TypeObject 'GenericAlias' at 0x18e91cc8>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x18ee9d00> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x18ee9d00> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x18ee9d00> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x18ee9d00> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xd51cee0>> w_obj = <W_TypeObject 'ellipsis' at 0x18ee9d00> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x18ee9d00>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xd51cee0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x18ee9d00> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xd51cee0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xd51cee0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xd51cee0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _________ ERROR at setup of AppTestRecompiler.test_global_var_array_2 __________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000014d60e30>, 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_global_var_array_2'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_global_var_array_2'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_global_var_array_2'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_global_var_array_2'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_global_var_array_2'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_global_var_array_2'>} 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_global_var_array_2'>, '__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 0x000000002ae69740> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ar_array_2'>, '__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 0x00000000126796a0> 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 0x00000000126796a0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ar_array_2'>, '__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_global_var_array_2'>, '__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_global_var_array_2'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000001aa9a250> key = (((True, True, True, 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 0x000000001aa9a250> 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 0x000000001aa9a250> 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 0x000000001aa9a250> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x00000000126a2aa0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000001a8bb440> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000001aa9a800>, <W_TypeObject 'GenericAlias' at 0x1cad5750>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x22fc9e18> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x22fc9e18> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x22fc9e18> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x22fc9e18> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x133c6400>> w_obj = <W_TypeObject 'ellipsis' at 0x22fc9e18> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x22fc9e18>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x133c6400>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x22fc9e18> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x133c6400>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x133c6400>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x133c6400>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError __________ ERROR at setup of AppTestRecompiler.test_some_integer_type __________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000001979f8f8>, 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_some_integer_type'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_some_integer_type'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_some_integer_type'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_some_integer_type'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_some_integer_type'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_some_integer_type'>} 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_some_integer_type'>, '__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 0x0000000018adb0b0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...teger_type'>, '__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 0x000000001e8ad6e0> 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 0x000000001e8ad6e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...teger_type'>, '__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_some_integer_type'>, '__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_some_integer_type'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000002365e218> key = (((True, True, True, 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 0x000000002365e218> 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 0x000000002365e218> 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 0x000000002365e218> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000001e8e6aa0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000028138ec8> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000002365e790>, <W_TypeObject 'GenericAlias' at 0x235b6c28>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1bbbf910> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1bbbf910> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1bbbf910> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1bbbf910> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13d33fa0>> w_obj = <W_TypeObject 'ellipsis' at 0x1bbbf910> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x1bbbf910>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13d33fa0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x1bbbf910> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13d33fa0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13d33fa0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13d33fa0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ______________ ERROR at setup of AppTestRecompiler.test_issue200 _______________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000020e40458>, 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_issue200'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_issue200'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_issue200'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_issue200'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_issue200'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_issue200'>} 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_issue200'>, '__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 0x0000000017711dd0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_issue200'>, '__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 0x0000000028ee8ca0> 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 0x0000000028ee8ca0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_issue200'>, '__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_issue200'>, '__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_issue200'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000029873d00> key = (((True, True, True, 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 0x0000000029873d00> 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 0x0000000029873d00> 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 0x0000000029873d00> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000028f242a0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000001c2d7e18> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000002989c2c0>, <W_TypeObject 'GenericAlias' at 0x28422480>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x284620c8> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x284620c8> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x284620c8> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x284620c8> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1dab3c30>> w_obj = <W_TypeObject 'ellipsis' at 0x284620c8> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x284620c8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1dab3c30>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x284620c8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1dab3c30>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1dab3c30>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1dab3c30>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ________ ERROR at setup of AppTestRecompiler.test_alignment_of_longlong ________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x00000000236063e0>, 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_alignment_of_longlong'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_alignment_of_longlong'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_alignment_of_longlong'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_alignment_of_longlong'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_alignment_of_longlong'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_alignment_of_longlong'>} 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_alignment_of_longlong'>, '__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 0x0000000015352818> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...f_longlong'>, '__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 0x0000000023d0ade0> 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 0x0000000023d0ade0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...f_longlong'>, '__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_alignment_of_longlong'>, '__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_alignment_of_longlong'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000018465f30> key = (((True, True, True, 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 0x0000000018465f30> 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 0x0000000018465f30> 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 0x0000000018465f30> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000029730120> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000296aef70> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000002741e4f0>, <W_TypeObject 'GenericAlias' at 0x1a1bcf00>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1937e800> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1937e800> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1937e800> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1937e800> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xa99fbc0>> w_obj = <W_TypeObject 'ellipsis' at 0x1937e800> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x1937e800>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xa99fbc0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x1937e800> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xa99fbc0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xa99fbc0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xa99fbc0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ___________ ERROR at setup of AppTestRecompiler.test_import_from_lib ___________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000002ae414c0>, 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_from_lib'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_import_from_lib'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_import_from_lib'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_import_from_lib'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_import_from_lib'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_import_from_lib'>} 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_from_lib'>, '__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 0x0000000019f13790> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_from_lib'>, '__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 0x000000001f38e3e0> 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 0x000000001f38e3e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_from_lib'>, '__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_from_lib'>, '__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_from_lib'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000002234c090> key = (((True, True, True, 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 0x000000002234c090> 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 0x000000002234c090> 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 0x000000002234c090> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000001f38f6a0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000021ecf590> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000002234c608>, <W_TypeObject 'GenericAlias' at 0x226d7948>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x26fb4e58> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x26fb4e58> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x26fb4e58> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x26fb4e58> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x9bdfba0>> w_obj = <W_TypeObject 'ellipsis' at 0x26fb4e58> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x26fb4e58>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x9bdfba0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x26fb4e58> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x9bdfba0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x9bdfba0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x9bdfba0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _________ ERROR at setup of AppTestRecompiler.test_macro_var_callback __________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000002214b5b0>, 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_macro_var_callback'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_macro_var_callback'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_macro_var_callback'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_macro_var_callback'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_macro_var_callback'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_macro_var_callback'>} 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_macro_var_callback'>, '__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 0x000000001af23a38> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...r_callback'>, '__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 0x000000002641c520> 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 0x000000002641c520> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...r_callback'>, '__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_macro_var_callback'>, '__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_macro_var_callback'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000002642f1a0> key = (((True, True, True, 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 0x000000002642f1a0> 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 0x000000002642f1a0> 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 0x000000002642f1a0> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000002641d760> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000028650640> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000002642f718>, <W_TypeObject 'GenericAlias' at 0x24cfe838>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1c38bbb0> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1c38bbb0> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1c38bbb0> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1c38bbb0> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0d2440>> w_obj = <W_TypeObject 'ellipsis' at 0x1c38bbb0> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x1c38bbb0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0d2440>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x1c38bbb0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0d2440>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0d2440>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0d2440>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ____________ ERROR at setup of AppTestRecompiler.test_const_fields _____________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000002c4d93d0>, 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_const_fields'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_const_fields'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_const_fields'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_const_fields'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_const_fields'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_const_fields'>} 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_const_fields'>, '__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 0x000000001dfdba88> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...nst_fields'>, '__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 0x000000002a609aa0> 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 0x000000002a609aa0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...nst_fields'>, '__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_const_fields'>, '__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_const_fields'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000002a643e50> key = (((True, True, True, 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 0x000000002a643e50> 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 0x000000002a643e50> 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 0x000000002a643e50> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000028072c60> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000296232b8> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000002808a410>, <W_TypeObject 'GenericAlias' at 0x2bfbd590>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2bfa0a30> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2bfa0a30> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2bfa0a30> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2bfa0a30> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x14949d40>> w_obj = <W_TypeObject 'ellipsis' at 0x2bfa0a30> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x2bfa0a30>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x14949d40>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x2bfa0a30> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x14949d40>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x14949d40>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x14949d40>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ___________ ERROR at setup of AppTestRecompiler.test_restrict_fields ___________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000002c174ae8>, 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_restrict_fields'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_restrict_fields'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_restrict_fields'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_restrict_fields'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_restrict_fields'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_restrict_fields'>} 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_restrict_fields'>, '__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 0x000000002bcb0c28> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ict_fields'>, '__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 0x000000000fe391e0> 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 0x000000000fe391e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ict_fields'>, '__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_restrict_fields'>, '__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_restrict_fields'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000017ca14b0> key = (((True, True, True, 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 0x0000000017ca14b0> 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 0x0000000017ca14b0> 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 0x0000000017ca14b0> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000000f5685a0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000017b06f38> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000017c9e138>, <W_TypeObject 'GenericAlias' at 0x17e28480>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1810efe0> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1810efe0> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1810efe0> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1810efe0> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x23e2aaf0>> w_obj = <W_TypeObject 'ellipsis' at 0x1810efe0> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x1810efe0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x23e2aaf0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x1810efe0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x23e2aaf0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x23e2aaf0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x23e2aaf0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ___________ ERROR at setup of AppTestRecompiler.test_volatile_fields ___________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x00000000161a1178>, 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_volatile_fields'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_volatile_fields'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_volatile_fields'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_volatile_fields'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_volatile_fields'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_volatile_fields'>} 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_volatile_fields'>, '__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 0x0000000023dc8340> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ile_fields'>, '__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 0x000000000a5615e0> 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 0x000000000a5615e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ile_fields'>, '__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_volatile_fields'>, '__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_volatile_fields'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x00000000249ecf70> key = (((True, True, True, 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 0x00000000249ecf70> 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 0x00000000249ecf70> 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 0x00000000249ecf70> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000000a44ec20> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000001aa93718> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x00000000249ed6e0>, <W_TypeObject 'GenericAlias' at 0x25203050>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x233dd1d8> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x233dd1d8> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x233dd1d8> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x233dd1d8> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xac023c0>> w_obj = <W_TypeObject 'ellipsis' at 0x233dd1d8> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x233dd1d8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xac023c0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x233dd1d8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xac023c0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xac023c0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xac023c0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _________ ERROR at setup of AppTestRecompiler.test_const_array_fields __________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000019876cc8>, 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_const_array_fields'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_const_array_fields'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_const_array_fields'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_const_array_fields'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_const_array_fields'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_const_array_fields'>} 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_const_array_fields'>, '__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 0x000000000a3a63e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ray_fields'>, '__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 0x000000001e7abd60> 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 0x000000001e7abd60> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ray_fields'>, '__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_const_array_fields'>, '__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_const_array_fields'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000001d500330> key = (((True, True, True, 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 0x000000001d500330> 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 0x000000001d500330> 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 0x000000001d500330> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000001e8e6b20> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000270f8170> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000001d5008a8>, <W_TypeObject 'GenericAlias' at 0x1bbbc288>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x278b6988> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x278b6988> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x278b6988> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x278b6988> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x139df700>> w_obj = <W_TypeObject 'ellipsis' at 0x278b6988> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x278b6988>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x139df700>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x278b6988> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x139df700>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x139df700>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x139df700>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ____ ERROR at setup of AppTestRecompiler.test_const_array_fields_varlength _____ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000020f7cb60>, 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_const_array_fields_varlength'>,...icall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_const_array_fields_varlength'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_const_array_fields_varlength'>,...icall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_const_array_fields_varlength'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_const_array_fields_varlength'>,...icall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_const_array_fields_varlength'>} 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_const_array_fields_varlength'>, '__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 0x0000000017507c90> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._varlength'>, '__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 0x000000002915c960> 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 0x000000002915c960> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._varlength'>, '__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_const_array_fields_varlength'>, '__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_const_array_fields_varlength'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000001d2988e0> key = (((True, True, True, 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 0x000000001d2988e0> 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 0x000000001d2988e0> 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 0x000000001d2988e0> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000002915dd60> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000001b972410> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000001d298ec8>, <W_TypeObject 'GenericAlias' at 0x1c58f2f0>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1c558f38> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1c558f38> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1c558f38> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1c558f38> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x78bd470>> w_obj = <W_TypeObject 'ellipsis' at 0x1c558f38> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x1c558f38>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x78bd470>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x1c558f38> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x78bd470>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x78bd470>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x78bd470>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError __ ERROR at setup of AppTestRecompiler.test_const_array_fields_unknownlength ___ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000026a4eea8>, 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_const_array_fields_unknownlengt...l__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_const_array_fields_unknownlength'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_const_array_fields_unknownlengt...l__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_const_array_fields_unknownlength'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_const_array_fields_unknownlengt...l__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_const_array_fields_unknownlength'>} 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_const_array_fields_unknownlength'>, '__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 0x00000000164cc598> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...nownlength'>, '__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 0x00000000279c3460> 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 0x00000000279c3460> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...nownlength'>, '__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_const_array_fields_unknownlength'>, '__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_const_array_fields_unknownlength'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000001a6b2c60> key = (((True, True, True, 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 0x000000001a6b2c60> 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 0x000000001a6b2c60> 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 0x000000001a6b2c60> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x00000000279826a0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000240c0640> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000001a6b31d8>, <W_TypeObject 'GenericAlias' at 0x19ff19b8>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2aa994e8> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2aa994e8> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2aa994e8> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2aa994e8> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x14a1eb90>> w_obj = <W_TypeObject 'ellipsis' at 0x2aa994e8> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x2aa994e8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x14a1eb90>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x2aa994e8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x14a1eb90>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x14a1eb90>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x14a1eb90>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _________ ERROR at setup of AppTestRecompiler.test_const_function_args _________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000027a4e548>, 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_const_function_args'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_const_function_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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_const_function_args'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_const_function_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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_const_function_args'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_const_function_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_const_function_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 0x0000000019c16f70> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ction_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 0x000000001befab60> 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 0x000000001befab60> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ction_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_const_function_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_const_function_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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000022457600> key = (((True, True, True, 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 0x0000000022457600> 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 0x0000000022457600> 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 0x0000000022457600> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000001befbd60> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000292d3be8> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000022457b78>, <W_TypeObject 'GenericAlias' at 0x2902fb08>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x24f890c0> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x24f890c0> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x24f890c0> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x24f890c0> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1c35e970>> w_obj = <W_TypeObject 'ellipsis' at 0x24f890c0> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x24f890c0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1c35e970>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x24f890c0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1c35e970>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1c35e970>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1c35e970>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ______ ERROR at setup of AppTestRecompiler.test_const_function_type_args _______ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000002ba62908>, 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_const_function_type_args'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_const_function_type_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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_const_function_type_args'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_const_function_type_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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_const_function_type_args'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_const_function_type_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_const_function_type_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 0x000000001ab74480> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._type_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 0x000000001fdee760> 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 0x000000001fdee760> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._type_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_const_function_type_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_const_function_type_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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000001fd9ef70> key = (((True, True, True, 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 0x000000001fd9ef70> 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 0x000000001fd9ef70> 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 0x000000001fd9ef70> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000001fdef820> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000002b06d670> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000001fd9f4e8>, <W_TypeObject 'GenericAlias' at 0x2c47c8e0>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2c4b02f8> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2c4b02f8> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2c4b02f8> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2c4b02f8> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x48e2630>> w_obj = <W_TypeObject 'ellipsis' at 0x2c4b02f8> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x2c4b02f8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x48e2630>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x2c4b02f8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x48e2630>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x48e2630>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x48e2630>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ___________ ERROR at setup of AppTestRecompiler.test_const_constant ____________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x00000000295f4a70>, 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_const_constant'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_const_constant'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_const_constant'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_const_constant'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_const_constant'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_const_constant'>} 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_const_constant'>, '__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 0x000000001d0869a8> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_constant'>, '__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 0x00000000288e95e0> 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 0x00000000288e95e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_constant'>, '__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_const_constant'>, '__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_const_constant'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000028891a60> key = (((True, True, True, 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 0x0000000028891a60> 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 0x0000000028891a60> 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 0x0000000028891a60> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000001c8f8760> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000002257cb48> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000023ca6020>, <W_TypeObject 'GenericAlias' at 0x1c10f050>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x27ee8020> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x27ee8020> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x27ee8020> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x27ee8020> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e9d270>> w_obj = <W_TypeObject 'ellipsis' at 0x27ee8020> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x27ee8020>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e9d270>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x27ee8020> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e9d270>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e9d270>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10e9d270>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError __________ ERROR at setup of AppTestRecompiler.test_const_via_typedef __________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000001d2f8368>, 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_const_via_typedef'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_const_via_typedef'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_const_via_typedef'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_const_via_typedef'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_const_via_typedef'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_const_via_typedef'>} 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_const_via_typedef'>, '__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 0x0000000020cbb150> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ia_typedef'>, '__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 0x000000000f5686e0> 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 0x000000000f5686e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ia_typedef'>, '__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_const_via_typedef'>, '__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_const_via_typedef'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000017c2b8d8> key = (((True, True, True, 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 0x0000000017c2b8d8> 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 0x0000000017c2b8d8> 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 0x0000000017c2b8d8> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000000f569c20> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000179e78d8> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000017c26950>, <W_TypeObject 'GenericAlias' at 0x18d21590>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x18e9b1a0> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x18e9b1a0> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x18e9b1a0> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x18e9b1a0> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xeb5cbd0>> w_obj = <W_TypeObject 'ellipsis' at 0x18e9b1a0> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x18e9b1a0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xeb5cbd0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x18e9b1a0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xeb5cbd0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xeb5cbd0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xeb5cbd0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _____ ERROR at setup of AppTestRecompiler.test_win32_calling_convention_0 ______ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000029ab5e20>, 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_win32_calling_convention_0'>, '...lticall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_win32_calling_convention_0'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_win32_calling_convention_0'>, '...lticall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_win32_calling_convention_0'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_win32_calling_convention_0'>, '...lticall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_win32_calling_convention_0'>} 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_win32_calling_convention_0'>, '__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 0x00000000242aca98> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...nvention_0'>, '__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 0x000000000a5fea20> 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 0x000000000a5fea20> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...nvention_0'>, '__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_win32_calling_convention_0'>, '__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_win32_calling_convention_0'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x00000000249c7ad0> key = (((True, True, True, 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 0x00000000249c7ad0> 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 0x00000000249c7ad0> 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 0x00000000249c7ad0> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000000a560a60> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000001aa98758> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x00000000249e8090>, <W_TypeObject 'GenericAlias' at 0x25202090>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x233dcec8> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x233dcec8> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x233dcec8> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x233dcec8> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10ac4fc0>> w_obj = <W_TypeObject 'ellipsis' at 0x233dcec8> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x233dcec8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10ac4fc0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x233dcec8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10ac4fc0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10ac4fc0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10ac4fc0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _____ ERROR at setup of AppTestRecompiler.test_win32_calling_convention_1 ______ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000019876098>, 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_win32_calling_convention_1'>, '...lticall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_win32_calling_convention_1'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_win32_calling_convention_1'>, '...lticall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_win32_calling_convention_1'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_win32_calling_convention_1'>, '...lticall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_win32_calling_convention_1'>} 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_win32_calling_convention_1'>, '__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 0x000000001be49ee8> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...nvention_1'>, '__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 0x000000001e6b08e0> 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 0x000000001e6b08e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...nvention_1'>, '__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_win32_calling_convention_1'>, '__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_win32_calling_convention_1'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000023d7b0c0> key = (((True, True, True, 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 0x0000000023d7b0c0> 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 0x0000000023d7b0c0> 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 0x0000000023d7b0c0> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000001e6b1ee0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000018df6138> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000023d7b638>, <W_TypeObject 'GenericAlias' at 0x21a39868>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2202f4e8> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2202f4e8> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2202f4e8> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2202f4e8> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xf8a7ba0>> w_obj = <W_TypeObject 'ellipsis' at 0x2202f4e8> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x2202f4e8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xf8a7ba0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x2202f4e8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xf8a7ba0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xf8a7ba0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xf8a7ba0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _____ ERROR at setup of AppTestRecompiler.test_win32_calling_convention_2 ______ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x00000000231c0ae8>, 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_win32_calling_convention_2'>, '...lticall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_win32_calling_convention_2'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_win32_calling_convention_2'>, '...lticall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_win32_calling_convention_2'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_win32_calling_convention_2'>, '...lticall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_win32_calling_convention_2'>} 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_win32_calling_convention_2'>, '__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 0x0000000005fc4840> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...nvention_2'>, '__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 0x000000001ec5cf20> 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 0x000000001ec5cf20> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...nvention_2'>, '__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_win32_calling_convention_2'>, '__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_win32_calling_convention_2'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000001a010838> key = (((True, True, True, 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 0x000000001a010838> 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 0x000000001a010838> 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 0x000000001a010838> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000001ec60060> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000024f14ad8> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000001a010db0>, <W_TypeObject 'GenericAlias' at 0x27be82f8>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1cc16e58> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1cc16e58> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1cc16e58> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1cc16e58> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11b74710>> w_obj = <W_TypeObject 'ellipsis' at 0x1cc16e58> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x1cc16e58>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11b74710>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x1cc16e58> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11b74710>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11b74710>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11b74710>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _____ ERROR at setup of AppTestRecompiler.test_win32_calling_convention_3 ______ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000027507da8>, 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_win32_calling_convention_3'>, '...lticall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_win32_calling_convention_3'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_win32_calling_convention_3'>, '...lticall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_win32_calling_convention_3'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_win32_calling_convention_3'>, '...lticall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_win32_calling_convention_3'>} 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_win32_calling_convention_3'>, '__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 0x0000000016887308> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...nvention_3'>, '__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 0x000000001f51a420> 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 0x000000001f51a420> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...nvention_3'>, '__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_win32_calling_convention_3'>, '__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_win32_calling_convention_3'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000029c39ec0> key = (((True, True, True, 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 0x0000000029c39ec0> 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 0x0000000029c39ec0> 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 0x0000000029c39ec0> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000001f51b8a0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000024fb8b80> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000029c4a480>, <W_TypeObject 'GenericAlias' at 0x1ed3e0c8>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2ae94de8> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2ae94de8> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2ae94de8> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2ae94de8> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x142c9440>> w_obj = <W_TypeObject 'ellipsis' at 0x2ae94de8> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x2ae94de8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x142c9440>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x2ae94de8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x142c9440>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x142c9440>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x142c9440>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _____________ ERROR at setup of AppTestRecompiler.test_share_FILE ______________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000025e9cc50>, 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_share_FILE'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_share_FILE'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_share_FILE'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_share_FILE'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_share_FILE'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_share_FILE'>} 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_share_FILE'>, '__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 0x0000000019940340> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...share_FILE'>, '__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 0x000000001f2b85a0> 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 0x000000001f2b85a0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...share_FILE'>, '__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_share_FILE'>, '__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_share_FILE'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000023217130> key = (((True, True, True, 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 0x0000000023217130> 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 0x0000000023217130> 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 0x0000000023217130> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000001f2982a0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000001eb2aa68> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000001d17c608>, <W_TypeObject 'GenericAlias' at 0x27e32720>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x27e2bda8> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x27e2bda8> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x27e2bda8> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x27e2bda8> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x14542fa0>> w_obj = <W_TypeObject 'ellipsis' at 0x27e2bda8> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x27e2bda8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x14542fa0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x27e2bda8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x14542fa0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x14542fa0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x14542fa0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ___________ ERROR at setup of AppTestRecompiler.test_extern_python_1 ___________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000001d316f20>, 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_extern_python_1'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_extern_python_1'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_extern_python_1'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_extern_python_1'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_extern_python_1'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_extern_python_1'>} 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_extern_python_1'>, '__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 0x000000001a7fdf88> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...n_python_1'>, '__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 0x000000002a3e4b20> 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 0x000000002a3e4b20> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...n_python_1'>, '__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_extern_python_1'>, '__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_extern_python_1'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000002a3c3670> key = (((True, True, True, 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 0x000000002a3c3670> 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 0x000000002a3c3670> 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 0x000000002a3c3670> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000002a3e5ea0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000023591910> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000002a3c3be8>, <W_TypeObject 'GenericAlias' at 0x20a7d600>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x20a90950> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x20a90950> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x20a90950> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x20a90950> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x9c0a6a0>> w_obj = <W_TypeObject 'ellipsis' at 0x20a90950> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x20a90950>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x9c0a6a0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x20a90950> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x9c0a6a0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x9c0a6a0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x9c0a6a0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ______ ERROR at setup of AppTestRecompiler.test_extern_python_bogus_name _______ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000001c89f010>, 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_extern_python_bogus_name'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_extern_python_bogus_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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_extern_python_bogus_name'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_extern_python_bogus_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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_extern_python_bogus_name'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_extern_python_bogus_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_extern_python_bogus_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 0x000000001c526458> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...bogus_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 0x0000000026e11060> 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 0x0000000026e11060> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...bogus_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_extern_python_bogus_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_extern_python_bogus_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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000026e15f68> key = (((True, True, True, 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 0x0000000026e15f68> 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 0x0000000026e15f68> 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 0x0000000026e15f68> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000026beb5e0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000029dd0a68> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000001d550528>, <W_TypeObject 'GenericAlias' at 0x1fcc8b80>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1f1b6f38> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1f1b6f38> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1f1b6f38> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1f1b6f38> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x614fd30>> w_obj = <W_TypeObject 'ellipsis' at 0x1f1b6f38> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x1f1b6f38>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x614fd30>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x1f1b6f38> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x614fd30>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x614fd30>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x614fd30>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ___ ERROR at setup of AppTestRecompiler.test_extern_python_bogus_result_type ___ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000002c053f10>, 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_extern_python_bogus_result_type...ll__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_extern_python_bogus_result_type'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_extern_python_bogus_result_type...ll__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_extern_python_bogus_result_type'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_extern_python_bogus_result_type...ll__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_extern_python_bogus_result_type'>} 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_extern_python_bogus_result_type'>, '__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 0x0000000020f782f0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...esult_type'>, '__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 0x000000000f5c0920> 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 0x000000000f5c0920> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...esult_type'>, '__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_extern_python_bogus_result_type'>, '__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_extern_python_bogus_result_type'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000017c70870> key = (((True, True, True, 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 0x0000000017c70870> 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 0x0000000017c70870> 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 0x0000000017c70870> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000000f5c1d60> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000017ad9ec0> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000017c70f70>, <W_TypeObject 'GenericAlias' at 0x18f04f38>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x18f55408> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x18f55408> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x18f55408> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x18f55408> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107356e0>> w_obj = <W_TypeObject 'ellipsis' at 0x18f55408> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x18f55408>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107356e0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x18f55408> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107356e0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107356e0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x107356e0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _______ ERROR at setup of AppTestRecompiler.test_extern_python_redefine ________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000028d69bc8>, 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_extern_python_redefine'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_extern_python_redefine'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_extern_python_redefine'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_extern_python_redefine'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_extern_python_redefine'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_extern_python_redefine'>} 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_extern_python_redefine'>, '__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 0x000000002480fb78> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...n_redefine'>, '__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 0x000000000a44f160> 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 0x000000000a44f160> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...n_redefine'>, '__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_extern_python_redefine'>, '__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_extern_python_redefine'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000024e9c790> key = (((True, True, True, 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 0x0000000024e9c790> 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 0x0000000024e9c790> 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 0x0000000024e9c790> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000000a742160> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000001ee46918> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000024e9cd08>, <W_TypeObject 'GenericAlias' at 0x22e31018>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1cb1e058> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1cb1e058> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1cb1e058> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1cb1e058> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x219bb2f0>> w_obj = <W_TypeObject 'ellipsis' at 0x1cb1e058> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x1cb1e058>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x219bb2f0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x1cb1e058> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x219bb2f0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x219bb2f0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x219bb2f0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ________ ERROR at setup of AppTestRecompiler.test_extern_python_struct _________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000019998f20>, 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_extern_python_struct'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_extern_python_struct'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_extern_python_struct'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_extern_python_struct'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_extern_python_struct'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_extern_python_struct'>} 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_extern_python_struct'>, '__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 0x000000002687b358> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...hon_struct'>, '__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 0x000000001e8e6960> 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 0x000000001e8e6960> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...hon_struct'>, '__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_extern_python_struct'>, '__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_extern_python_struct'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000029c65f30> key = (((True, True, True, 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 0x0000000029c65f30> 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 0x0000000029c65f30> 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 0x0000000029c65f30> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000001e8e7ca0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000002602c058> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000001f2c64f0>, <W_TypeObject 'GenericAlias' at 0x236f8560>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x27131cc8> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x27131cc8> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x27131cc8> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x27131cc8> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10c27b70>> w_obj = <W_TypeObject 'ellipsis' at 0x27131cc8> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x27131cc8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10c27b70>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x27131cc8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10c27b70>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10c27b70>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x10c27b70>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ______ ERROR at setup of AppTestRecompiler.test_extern_python_long_double ______ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000024612b60>, 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_extern_python_long_double'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_extern_python_long_double'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_extern_python_long_double'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_extern_python_long_double'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_extern_python_long_double'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_extern_python_long_double'>} 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_extern_python_long_double'>, '__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 0x0000000016ff7038> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ong_double'>, '__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 0x00000000291696a0> 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 0x00000000291696a0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ong_double'>, '__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_extern_python_long_double'>, '__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_extern_python_long_double'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000002928a170> key = (((True, True, True, 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 0x000000002928a170> 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 0x000000002928a170> 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 0x000000002928a170> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000029156b60> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000001b500c28> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000002928a6e8>, <W_TypeObject 'GenericAlias' at 0x27175a60>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x235c3d38> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x235c3d38> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x235c3d38> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x235c3d38> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xf8d78a0>> w_obj = <W_TypeObject 'ellipsis' at 0x235c3d38> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x235c3d38>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xf8d78a0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x235c3d38> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xf8d78a0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xf8d78a0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xf8d78a0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _______ ERROR at setup of AppTestRecompiler.test_extern_python_signature _______ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000001d8aa020>, 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_extern_python_signature'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_extern_python_signature'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_extern_python_signature'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_extern_python_signature'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_extern_python_signature'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_extern_python_signature'>} 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_extern_python_signature'>, '__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 0x000000001680dc90> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._signature'>, '__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 0x0000000023d00ce0> 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 0x0000000023d00ce0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._signature'>, '__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_extern_python_signature'>, '__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_extern_python_signature'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000002012e410> key = (((True, True, True, 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 0x000000002012e410> 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 0x000000002012e410> 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 0x000000002012e410> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000023d01e60> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000001f858330> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000002012e988>, <W_TypeObject 'GenericAlias' at 0x1cb51558>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1cb78678> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1cb78678> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1cb78678> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1cb78678> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x483b470>> w_obj = <W_TypeObject 'ellipsis' at 0x1cb78678> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x1cb78678>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x483b470>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x1cb78678> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x483b470>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x483b470>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x483b470>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ________ ERROR at setup of AppTestRecompiler.test_extern_python_errors _________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000002214a890>, 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_extern_python_errors'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_extern_python_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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_extern_python_errors'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_extern_python_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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_extern_python_errors'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_extern_python_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_extern_python_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 0x00000000197891c8> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...hon_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 0x000000001becd7a0> 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 0x000000001becd7a0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...hon_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_extern_python_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_extern_python_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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x00000000193f1788> key = (((True, True, True, 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 0x00000000193f1788> 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 0x00000000193f1788> 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 0x00000000193f1788> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000001bf20ae0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000024e1a528> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x00000000193f1d00>, <W_TypeObject 'GenericAlias' at 0x17c0e560>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x17bf0528> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x17bf0528> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x17bf0528> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x17bf0528> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x24a85dc0>> w_obj = <W_TypeObject 'ellipsis' at 0x17bf0528> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x17bf0528>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x24a85dc0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x17bf0528> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x24a85dc0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x24a85dc0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x24a85dc0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ________ ERROR at setup of AppTestRecompiler.test_extern_python_stdcall ________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000002c4d84d0>, 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_extern_python_stdcall'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_extern_python_stdcall'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_extern_python_stdcall'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_extern_python_stdcall'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_extern_python_stdcall'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_extern_python_stdcall'>} 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_extern_python_stdcall'>, '__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 0x000000001a62df60> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...on_stdcall'>, '__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 0x000000002b8b6be0> 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 0x000000002b8b6be0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...on_stdcall'>, '__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_extern_python_stdcall'>, '__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_extern_python_stdcall'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000001bfc0598> key = (((True, True, True, 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 0x000000001bfc0598> 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 0x000000001bfc0598> 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 0x000000001bfc0598> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000002b8b7ce0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000027ebc9c0> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000001bfc0b10>, <W_TypeObject 'GenericAlias' at 0x28bb6800>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x29324410> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x29324410> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x29324410> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x29324410> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1dd2b260>> w_obj = <W_TypeObject 'ellipsis' at 0x29324410> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x29324410>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1dd2b260>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x29324410> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1dd2b260>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1dd2b260>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1dd2b260>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _________ ERROR at setup of AppTestRecompiler.test_introspect_function _________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000001c1152e0>, 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_introspect_function'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_introspect_function'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_introspect_function'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_introspect_function'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_introspect_function'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_introspect_function'>} 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_introspect_function'>, '__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 0x000000001bb27650> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_function'>, '__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 0x000000001fc150a0> 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 0x000000001fc150a0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_function'>, '__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_introspect_function'>, '__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_introspect_function'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000001fc91fa0> key = (((True, True, True, 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 0x000000001fc91fa0> 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 0x000000001fc91fa0> 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 0x000000001fc91fa0> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x00000000262be360> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000002babe4f0> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000001d772560>, <W_TypeObject 'GenericAlias' at 0x2c77f558>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x26616410> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x26616410> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x26616410> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x26616410> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x8972390>> w_obj = <W_TypeObject 'ellipsis' at 0x26616410> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x26616410>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x8972390>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x26616410> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x8972390>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x8972390>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x8972390>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ________ ERROR at setup of AppTestRecompiler.test_introspect_global_var ________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000007da07a0>, 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_introspect_global_var'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_introspect_global_var'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_introspect_global_var'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_introspect_global_var'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_introspect_global_var'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_introspect_global_var'>} 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_introspect_global_var'>, '__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 0x000000002b9f8610> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...global_var'>, '__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 0x00000000111bd0a0> 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 0x00000000111bd0a0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...global_var'>, '__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_introspect_global_var'>, '__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_introspect_global_var'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000001884d1d8> key = (((True, True, True, 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 0x000000001884d1d8> 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 0x000000001884d1d8> 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 0x000000001884d1d8> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000015384b60> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000018209088> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x00000000188ffbb0>, <W_TypeObject 'GenericAlias' at 0x1862d018>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1854b168> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1854b168> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1854b168> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1854b168> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b64fc0>> w_obj = <W_TypeObject 'ellipsis' at 0x1854b168> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x1854b168>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b64fc0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x1854b168> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b64fc0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b64fc0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1b64fc0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _____ ERROR at setup of AppTestRecompiler.test_introspect_global_var_array _____ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000002c175da8>, 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_introspect_global_var_array'>, ...ticall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_introspect_global_var_array'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_introspect_global_var_array'>, ...ticall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_introspect_global_var_array'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_introspect_global_var_array'>, ...ticall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_introspect_global_var_array'>} 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_introspect_global_var_array'>, '__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 0x0000000024b1c570> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._var_array'>, '__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 0x000000000684dba0> 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 0x000000000684dba0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._var_array'>, '__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_introspect_global_var_array'>, '__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_introspect_global_var_array'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000023f76f38> key = (((True, True, True, 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 0x0000000023f76f38> 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 0x0000000023f76f38> 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 0x0000000023f76f38> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000000b279960> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000249ed670> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000023f8ef00>, <W_TypeObject 'GenericAlias' at 0x203bbf30>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1dd91b08> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1dd91b08> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1dd91b08> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1dd91b08> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xfabe9c0>> w_obj = <W_TypeObject 'ellipsis' at 0x1dd91b08> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x1dd91b08>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xfabe9c0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x1dd91b08> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xfabe9c0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xfabe9c0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xfabe9c0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ______ ERROR at setup of AppTestRecompiler.test_introspect_integer_const _______ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000011539880>, 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_introspect_integer_const'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_introspect_integer_const'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_introspect_integer_const'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_introspect_integer_const'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_introspect_integer_const'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_introspect_integer_const'>} 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_introspect_integer_const'>, '__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 0x0000000027537b50> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...eger_const'>, '__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 0x000000001e56efe0> 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 0x000000001e56efe0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...eger_const'>, '__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_introspect_integer_const'>, '__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_introspect_integer_const'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000029908288> key = (((True, True, True, 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 0x0000000029908288> 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 0x0000000029908288> 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 0x0000000029908288> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000001e6b0860> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000029d61f30> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000029908800>, <W_TypeObject 'GenericAlias' at 0x1fa50448>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x268027c8> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x268027c8> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x268027c8> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x268027c8> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x217c2c00>> w_obj = <W_TypeObject 'ellipsis' at 0x268027c8> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x268027c8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x217c2c00>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x268027c8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x217c2c00>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x217c2c00>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x217c2c00>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _________ ERROR at setup of AppTestRecompiler.test_introspect_typedef __________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000001e2524d0>, 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_introspect_typedef'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_introspect_typedef'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_introspect_typedef'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_introspect_typedef'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_introspect_typedef'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_introspect_typedef'>} 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_introspect_typedef'>, '__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 0x00000000185ea868> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ct_typedef'>, '__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 0x0000000022c1fa20> 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 0x0000000022c1fa20> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ct_typedef'>, '__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_introspect_typedef'>, '__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_introspect_typedef'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000018e47ec0> key = (((True, True, True, 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 0x0000000018e47ec0> 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 0x0000000018e47ec0> 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 0x0000000018e47ec0> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000001fbd93a0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000281339f0> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000018dee480>, <W_TypeObject 'GenericAlias' at 0x269e0138>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2b775da8> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2b775da8> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2b775da8> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2b775da8> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20e6a630>> w_obj = <W_TypeObject 'ellipsis' at 0x2b775da8> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x2b775da8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20e6a630>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x2b775da8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20e6a630>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20e6a630>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20e6a630>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _____ ERROR at setup of AppTestRecompiler.test_introspect_typedef_multiple _____ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x00000000261dabd8>, 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_introspect_typedef_multiple'>, ...ticall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_introspect_typedef_multiple'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_introspect_typedef_multiple'>, ...ticall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_introspect_typedef_multiple'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_introspect_typedef_multiple'>, ...ticall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_introspect_typedef_multiple'>} 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_introspect_typedef_multiple'>, '__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 0x000000000e766700> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...f_multiple'>, '__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 0x0000000018e076e0> 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 0x0000000018e076e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...f_multiple'>, '__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_introspect_typedef_multiple'>, '__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_introspect_typedef_multiple'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x00000000184b0608> key = (((True, True, True, 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 0x00000000184b0608> 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 0x00000000184b0608> 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 0x00000000184b0608> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000018e427a0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000001ed692b8> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x00000000184b0b80>, <W_TypeObject 'GenericAlias' at 0x1ef1b8a0>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1ef52090> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1ef52090> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1ef52090> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1ef52090> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1f8b8b00>> w_obj = <W_TypeObject 'ellipsis' at 0x1ef52090> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x1ef52090>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1f8b8b00>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x1ef52090> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1f8b8b00>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1f8b8b00>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1f8b8b00>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError __________ ERROR at setup of AppTestRecompiler.test_introspect_struct __________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000025e9cea8>, 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_introspect_struct'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_introspect_struct'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_introspect_struct'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_introspect_struct'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_introspect_struct'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_introspect_struct'>} 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_introspect_struct'>, '__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 0x00000000152ca778> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ect_struct'>, '__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 0x000000001f2e6560> 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 0x000000001f2e6560> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ect_struct'>, '__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_introspect_struct'>, '__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_introspect_struct'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000001e68d670> key = (((True, True, True, 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 0x000000001e68d670> 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 0x000000001e68d670> 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 0x000000001e68d670> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000001f2e7c60> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000026fe1a98> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000001e68dbe8>, <W_TypeObject 'GenericAlias' at 0x181376e0>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x20c16c60> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x20c16c60> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x20c16c60> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x20c16c60> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xf2bd370>> w_obj = <W_TypeObject 'ellipsis' at 0x20c16c60> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x20c16c60>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xf2bd370>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x20c16c60> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xf2bd370>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xf2bd370>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xf2bd370>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError __________ ERROR at setup of AppTestRecompiler.test_introspect_union ___________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000001f47e368>, 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_introspect_union'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_introspect_union'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_introspect_union'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_introspect_union'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_introspect_union'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_introspect_union'>} 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_introspect_union'>, '__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 0x000000001a4bc930> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...pect_union'>, '__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 0x0000000023a081e0> 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 0x0000000023a081e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...pect_union'>, '__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_introspect_union'>, '__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_introspect_union'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000023a3f520> key = (((True, True, True, 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 0x0000000023a3f520> 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 0x0000000023a3f520> 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 0x0000000023a3f520> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000023a094a0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000284dfda8> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000023a3fa98>, <W_TypeObject 'GenericAlias' at 0x210314e8>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x210023d8> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x210023d8> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x210023d8> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x210023d8> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x24ee7020>> w_obj = <W_TypeObject 'ellipsis' at 0x210023d8> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x210023d8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x24ee7020>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x210023d8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x24ee7020>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x24ee7020>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x24ee7020>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ____ ERROR at setup of AppTestRecompiler.test_introspect_struct_and_typedef ____ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000022531cb8>, 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_introspect_struct_and_typedef'>...call__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_introspect_struct_and_typedef'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_introspect_struct_and_typedef'>...call__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_introspect_struct_and_typedef'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_introspect_struct_and_typedef'>...call__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_introspect_struct_and_typedef'>} 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_introspect_struct_and_typedef'>, '__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 0x000000001b7d4750> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...nd_typedef'>, '__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 0x000000002527dee0> 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 0x000000002527dee0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...nd_typedef'>, '__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_introspect_struct_and_typedef'>, '__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_introspect_struct_and_typedef'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000025274640> key = (((True, True, True, 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 0x0000000025274640> 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 0x0000000025274640> 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 0x0000000025274640> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000021cd7a20> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000001fa97c90> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000021c860c8>, <W_TypeObject 'GenericAlias' at 0x29f28870>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x29f54bf0> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x29f54bf0> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x29f54bf0> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x29f54bf0> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1ea5f9a0>> w_obj = <W_TypeObject 'ellipsis' at 0x29f54bf0> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x29f54bf0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1ea5f9a0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x29f54bf0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1ea5f9a0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1ea5f9a0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1ea5f9a0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ______ ERROR at setup of AppTestRecompiler.test_introspect_included_type _______ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000002664ad40>, 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_introspect_included_type'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_introspect_included_type'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_introspect_included_type'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_introspect_included_type'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_introspect_included_type'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_introspect_included_type'>} 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_introspect_included_type'>, '__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 0x000000001ea7f7e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...luded_type'>, '__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 0x0000000015384420> 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 0x0000000015384420> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...luded_type'>, '__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_introspect_included_type'>, '__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_introspect_included_type'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000015cdc5d0> key = (((True, True, True, 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 0x0000000015cdc5d0> 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 0x0000000015cdc5d0> 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 0x0000000015cdc5d0> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x00000000153857e0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000000a5487c8> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000016427788>, <W_TypeObject 'GenericAlias' at 0x16541868>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x177091a0> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x177091a0> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x177091a0> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x177091a0> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x8283070>> w_obj = <W_TypeObject 'ellipsis' at 0x177091a0> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x177091a0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x8283070>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x177091a0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x8283070>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x8283070>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x8283070>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError __________ ERROR at setup of AppTestRecompiler.test_introspect_order ___________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000002c175970>, 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_introspect_order'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_introspect_order'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_introspect_order'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_introspect_order'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_introspect_order'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_introspect_order'>} 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_introspect_order'>, '__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 0x0000000024e513d0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...pect_order'>, '__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 0x0000000008983160> 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 0x0000000008983160> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...pect_order'>, '__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_introspect_order'>, '__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_introspect_order'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x00000000234c1210> key = (((True, True, True, 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 0x00000000234c1210> 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 0x00000000234c1210> 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 0x00000000234c1210> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000007c76aa0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000002460afe0> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x00000000234c1788>, <W_TypeObject 'GenericAlias' at 0x1d9269c0>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1cc1caa0> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1cc1caa0> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1cc1caa0> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1cc1caa0> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1193ace0>> w_obj = <W_TypeObject 'ellipsis' at 0x1cc1caa0> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x1cc1caa0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1193ace0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x1cc1caa0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1193ace0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1193ace0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1193ace0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _________ ERROR at setup of AppTestRecompiler.test_FFIFunctionWrapper __________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000024f67790>, 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_FFIFunctionWrapper'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_FFIFunctionWrapper'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_FFIFunctionWrapper'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_FFIFunctionWrapper'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_FFIFunctionWrapper'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_FFIFunctionWrapper'>} 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_FFIFunctionWrapper'>, '__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 0x0000000027622ca0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ionWrapper'>, '__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 0x000000001e2997e0> 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 0x000000001e2997e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ionWrapper'>, '__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_FFIFunctionWrapper'>, '__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_FFIFunctionWrapper'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000025021f30> key = (((True, True, True, 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 0x0000000025021f30> 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 0x0000000025021f30> 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 0x0000000025021f30> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000001e31ca60> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000020793ec0> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000002502cec8>, <W_TypeObject 'GenericAlias' at 0x22ceed40>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2a56dfa0> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2a56dfa0> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2a56dfa0> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2a56dfa0> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1ba9dd70>> w_obj = <W_TypeObject 'ellipsis' at 0x2a56dfa0> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x2a56dfa0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1ba9dd70>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x2a56dfa0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1ba9dd70>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1ba9dd70>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1ba9dd70>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ___ ERROR at setup of AppTestRecompiler.test_function_returns_float_complex ____ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000020f4ff10>, 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_function_returns_float_complex'...all__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_function_returns_float_complex'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_function_returns_float_complex'...all__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_function_returns_float_complex'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_function_returns_float_complex'...all__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_function_returns_float_complex'>} 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_function_returns_float_complex'>, '__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 0x0000000018614340> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...at_complex'>, '__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 0x0000000028fc7ea0> 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 0x0000000028fc7ea0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...at_complex'>, '__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_function_returns_float_complex'>, '__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_function_returns_float_complex'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000029f07910> key = (((True, True, True, 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 0x0000000029f07910> 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 0x0000000029f07910> 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 0x0000000029f07910> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x00000000290ab560> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000024118fa8> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000002b154170>, <W_TypeObject 'GenericAlias' at 0x23e5e170>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x24fd4bb8> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x24fd4bb8> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x24fd4bb8> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x24fd4bb8> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0d4570>> w_obj = <W_TypeObject 'ellipsis' at 0x24fd4bb8> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x24fd4bb8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0d4570>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x24fd4bb8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0d4570>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0d4570>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e0d4570>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ___ ERROR at setup of AppTestRecompiler.test_function_returns_double_complex ___ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000002636bc40>, 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_function_returns_double_complex...ll__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_function_returns_double_complex'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_function_returns_double_complex...ll__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_function_returns_double_complex'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_function_returns_double_complex...ll__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_function_returns_double_complex'>} 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_function_returns_double_complex'>, '__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 0x0000000016b33718> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...le_complex'>, '__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 0x00000000279c3f60> 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 0x00000000279c3f60> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...le_complex'>, '__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_function_returns_double_complex'>, '__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_function_returns_double_complex'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000001fa6d210> key = (((True, True, True, 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 0x000000001fa6d210> 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 0x000000001fa6d210> 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 0x000000001fa6d210> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x00000000279831e0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000276dcfe0> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000001fa6d788>, <W_TypeObject 'GenericAlias' at 0x1efbe988>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1beb5d00> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1beb5d00> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1beb5d00> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1beb5d00> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x96040e0>> w_obj = <W_TypeObject 'ellipsis' at 0x1beb5d00> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x1beb5d00>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x96040e0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x1beb5d00> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x96040e0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x96040e0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x96040e0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ___ ERROR at setup of AppTestRecompiler.test_function_argument_float_complex ___ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000002275fe98>, 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_function_argument_float_complex...ll__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_function_argument_float_complex'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_function_argument_float_complex...ll__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_function_argument_float_complex'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_function_argument_float_complex...ll__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_function_argument_float_complex'>} 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_function_argument_float_complex'>, '__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 0x0000000015788700> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...at_complex'>, '__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 0x0000000029ce1ba0> 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 0x0000000029ce1ba0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...at_complex'>, '__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_function_argument_float_complex'>, '__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_function_argument_float_complex'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000029942020> key = (((True, True, True, 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 0x0000000029942020> 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 0x0000000029942020> 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 0x0000000029942020> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000002b7a56e0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000022af77f8> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000029943a28>, <W_TypeObject 'GenericAlias' at 0x2b007cc8>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2b02bc90> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2b02bc90> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2b02bc90> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2b02bc90> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fa4190>> w_obj = <W_TypeObject 'ellipsis' at 0x2b02bc90> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x2b02bc90>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fa4190>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x2b02bc90> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fa4190>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fa4190>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fa4190>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError __ ERROR at setup of AppTestRecompiler.test_function_argument_double_complex ___ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x00000000295f59e8>, 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_function_argument_double_comple...l__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_function_argument_double_complex'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_function_argument_double_comple...l__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_function_argument_double_complex'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_function_argument_double_comple...l__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_function_argument_double_complex'>} 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_function_argument_double_complex'>, '__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 0x000000001a41a2f0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...le_complex'>, '__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 0x0000000024c34520> 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 0x0000000024c34520> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...le_complex'>, '__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_function_argument_double_complex'>, '__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_function_argument_double_complex'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000002278ee58> key = (((True, True, True, 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 0x000000002278ee58> 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 0x000000002278ee58> 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 0x000000002278ee58> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000024c35860> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000001d23ad40> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000002278f3d0>, <W_TypeObject 'GenericAlias' at 0x26c64058>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x291d5478> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x291d5478> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x291d5478> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x291d5478> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13af9330>> w_obj = <W_TypeObject 'ellipsis' at 0x291d5478> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x291d5478>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13af9330>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x291d5478> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13af9330>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13af9330>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13af9330>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _______ ERROR at setup of AppTestRecompiler.test_typedef_array_dotdotdot _______ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000002ba718f8>, 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_typedef_array_dotdotdot'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_typedef_array_dotdotdot'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_typedef_array_dotdotdot'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_typedef_array_dotdotdot'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_typedef_array_dotdotdot'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_typedef_array_dotdotdot'>} 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_typedef_array_dotdotdot'>, '__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 0x000000001b7524f8> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._dotdotdot'>, '__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 0x000000001f1e7460> 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 0x000000001f1e7460> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._dotdotdot'>, '__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_typedef_array_dotdotdot'>, '__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_typedef_array_dotdotdot'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x00000000252db6e0> key = (((True, True, True, 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 0x00000000252db6e0> 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 0x00000000252db6e0> 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 0x00000000252db6e0> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000002c714f20> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000001f058c98> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000002c758db0>, <W_TypeObject 'GenericAlias' at 0x23722410>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1fc65c20> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1fc65c20> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1fc65c20> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1fc65c20> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x6467640>> w_obj = <W_TypeObject 'ellipsis' at 0x1fc65c20> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x1fc65c20>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x6467640>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x1fc65c20> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x6467640>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x6467640>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x6467640>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _____ ERROR at setup of AppTestRecompiler.test_call_with_custom_field_pos ______ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000002a087f88>, 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_call_with_custom_field_pos'>, '...lticall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_call_with_custom_field_pos'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_call_with_custom_field_pos'>, '...lticall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_call_with_custom_field_pos'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_call_with_custom_field_pos'>, '...lticall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_call_with_custom_field_pos'>} 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_call_with_custom_field_pos'>, '__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 0x000000002cff8700> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._field_pos'>, '__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 0x0000000001b28ba0> 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 0x0000000001b28ba0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._field_pos'>, '__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_call_with_custom_field_pos'>, '__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_call_with_custom_field_pos'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000001d4449c0> key = (((True, True, True, 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 0x000000001d4449c0> 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 0x000000001d4449c0> 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 0x000000001d4449c0> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000012224ea0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000118c9788> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000001d444f38>, <W_TypeObject 'GenericAlias' at 0x17b19168>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x17abb1a0> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x17abb1a0> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x17abb1a0> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x17abb1a0> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1edd1ba0>> w_obj = <W_TypeObject 'ellipsis' at 0x17abb1a0> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x17abb1a0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1edd1ba0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x17abb1a0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1edd1ba0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1edd1ba0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1edd1ba0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError __ ERROR at setup of AppTestRecompiler.test_call_with_nested_anonymous_struct __ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000002c174368>, 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_call_with_nested_anonymous_stru...__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_call_with_nested_anonymous_struct'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_call_with_nested_anonymous_stru...__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_call_with_nested_anonymous_struct'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_call_with_nested_anonymous_stru...__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_call_with_nested_anonymous_struct'>} 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_call_with_nested_anonymous_struct'>, '__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 0x0000000021513dd0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ous_struct'>, '__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 0x000000000d44d960> 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 0x000000000d44d960> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ous_struct'>, '__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_call_with_nested_anonymous_struct'>, '__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_call_with_nested_anonymous_struct'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x00000000213c43a0> key = (((True, True, True, 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 0x00000000213c43a0> 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 0x00000000213c43a0> 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 0x00000000213c43a0> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000000de9dc60> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000021d6ef70> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x00000000213c4918>, <W_TypeObject 'GenericAlias' at 0x1a8b1a60>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1840e448> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1840e448> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1840e448> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1840e448> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xd50c310>> w_obj = <W_TypeObject 'ellipsis' at 0x1840e448> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x1840e448>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xd50c310>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x1840e448> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xd50c310>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xd50c310>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xd50c310>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _________ ERROR at setup of AppTestRecompiler.test_call_with_bitfield __________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000024f67628>, 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_call_with_bitfield'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_call_with_bitfield'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_call_with_bitfield'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_call_with_bitfield'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_call_with_bitfield'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_call_with_bitfield'>} 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_call_with_bitfield'>, '__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 0x0000000029a366d8> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...h_bitfield'>, '__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 0x000000001dfcdea0> 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 0x000000001dfcdea0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...h_bitfield'>, '__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_call_with_bitfield'>, '__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_call_with_bitfield'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000001c66b130> key = (((True, True, True, 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 0x000000001c66b130> 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 0x000000001c66b130> 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 0x000000001c66b130> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000001e00d060> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000019ab02c0> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000001c66b6a8>, <W_TypeObject 'GenericAlias' at 0x202a0a30>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1ec99a28> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1ec99a28> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1ec99a28> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1ec99a28> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x6dbc320>> w_obj = <W_TypeObject 'ellipsis' at 0x1ec99a28> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x1ec99a28>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x6dbc320>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x1ec99a28> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x6dbc320>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x6dbc320>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x6dbc320>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _____ ERROR at setup of AppTestRecompiler.test_call_with_zero_length_field _____ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000021751538>, 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_call_with_zero_length_field'>, ...ticall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_call_with_zero_length_field'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_call_with_zero_length_field'>, ...ticall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_call_with_zero_length_field'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_call_with_zero_length_field'>, ...ticall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_call_with_zero_length_field'>} 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_call_with_zero_length_field'>, '__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 0x0000000018beb948> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ngth_field'>, '__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 0x000000002799e9e0> 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 0x000000002799e9e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ngth_field'>, '__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_call_with_zero_length_field'>, '__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_call_with_zero_length_field'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000022744100> key = (((True, True, True, 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 0x0000000022744100> 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 0x0000000022744100> 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 0x0000000022744100> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000002799fbe0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000001f7fcbb8> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000022744678>, <W_TypeObject 'GenericAlias' at 0x26eabbe8>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x257ad600> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x257ad600> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x257ad600> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x257ad600> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11429dd0>> w_obj = <W_TypeObject 'ellipsis' at 0x257ad600> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x257ad600>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11429dd0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x257ad600> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11429dd0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11429dd0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x11429dd0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ___________ ERROR at setup of AppTestRecompiler.test_call_with_union ___________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000001f5ac4d0>, 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_call_with_union'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_call_with_union'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_call_with_union'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_call_with_union'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_call_with_union'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_call_with_union'>} 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_call_with_union'>, '__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 0x00000000164d5470> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...with_union'>, '__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 0x0000000027961b20> 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 0x0000000027961b20> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...with_union'>, '__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_call_with_union'>, '__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_call_with_union'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000025a70448> key = (((True, True, True, 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 0x0000000025a70448> 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 0x0000000025a70448> 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 0x0000000025a70448> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000027962e20> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000001c4d4790> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000025a709c0>, <W_TypeObject 'GenericAlias' at 0x26f76fa8>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x20449280> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x20449280> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x20449280> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x20449280> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x14874c20>> w_obj = <W_TypeObject 'ellipsis' at 0x20449280> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x20449280>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x14874c20>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x20449280> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x14874c20>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x14874c20>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x14874c20>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _______ ERROR at setup of AppTestRecompiler.test_call_with_packed_struct _______ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000002a3b6a70>, 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_call_with_packed_struct'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_call_with_packed_struct'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_call_with_packed_struct'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_call_with_packed_struct'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_call_with_packed_struct'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_call_with_packed_struct'>} 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_call_with_packed_struct'>, '__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 0x00000000160eae58> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ked_struct'>, '__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 0x000000001becd820> 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 0x000000001becd820> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ked_struct'>, '__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_call_with_packed_struct'>, '__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_call_with_packed_struct'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000001d87ade8> key = (((True, True, True, 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 0x000000001d87ade8> 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 0x000000001d87ade8> 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 0x000000001d87ade8> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000001bf20b60> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000001d1aa608> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000001d87b360>, <W_TypeObject 'GenericAlias' at 0x1e2806b0>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e26d6e0> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e26d6e0> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e26d6e0> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1e26d6e0> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e716080>> w_obj = <W_TypeObject 'ellipsis' at 0x1e26d6e0> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x1e26d6e0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e716080>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x1e26d6e0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e716080>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e716080>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e716080>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ________ ERROR at setup of AppTestRecompiler.test_gcc_visibility_hidden ________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000001c907880>, 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_gcc_visibility_hidden'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_gcc_visibility_hidden'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_gcc_visibility_hidden'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_gcc_visibility_hidden'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_gcc_visibility_hidden'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_gcc_visibility_hidden'>} 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_gcc_visibility_hidden'>, '__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 0x000000001a0cc3e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ity_hidden'>, '__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 0x00000000205eb060> 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 0x00000000205eb060> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ity_hidden'>, '__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_gcc_visibility_hidden'>, '__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_gcc_visibility_hidden'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000002a5299b8> key = (((True, True, True, 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 0x000000002a5299b8> 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 0x000000002a5299b8> 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 0x000000002a5299b8> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000001d218d20> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000028472db0> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000002935f3d0>, <W_TypeObject 'GenericAlias' at 0x2b5aac28>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x22f585d0> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x22f585d0> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x22f585d0> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x22f585d0> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x74430b0>> w_obj = <W_TypeObject 'ellipsis' at 0x22f585d0> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x22f585d0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x74430b0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x22f585d0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x74430b0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x74430b0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x74430b0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _____ ERROR at setup of AppTestRecompiler.test_override_default_definition _____ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000002c5226b0>, 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_override_default_definition'>, ...ticall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_override_default_definition'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_override_default_definition'>, ...ticall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_override_default_definition'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_override_default_definition'>, ...ticall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_override_default_definition'>} 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_override_default_definition'>, '__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 0x000000001b35f9c0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...definition'>, '__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 0x000000002348d0e0> 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 0x000000002348d0e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...definition'>, '__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_override_default_definition'>, '__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_override_default_definition'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x00000000234504f0> key = (((True, True, True, 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 0x00000000234504f0> 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 0x00000000234504f0> 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 0x00000000234504f0> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000002a24e220> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000002a2261a8> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000023450a68>, <W_TypeObject 'GenericAlias' at 0x2ad3fcc8>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2b530bf0> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2b530bf0> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2b530bf0> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2b530bf0> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x817bba0>> w_obj = <W_TypeObject 'ellipsis' at 0x2b530bf0> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x2b530bf0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x817bba0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x2b530bf0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x817bba0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x817bba0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x817bba0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ________ ERROR at setup of AppTestRecompiler.test_char16_char32_plain_c ________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000001f05b2e0>, 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_char16_char32_plain_c'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_char16_char32_plain_c'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_char16_char32_plain_c'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_char16_char32_plain_c'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_char16_char32_plain_c'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_char16_char32_plain_c'>} 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_char16_char32_plain_c'>, '__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 0x000000001dd6a228> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...32_plain_c'>, '__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 0x0000000025ab47e0> 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 0x0000000025ab47e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...32_plain_c'>, '__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_char16_char32_plain_c'>, '__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_char16_char32_plain_c'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000002417d830> key = (((True, True, True, 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 0x000000002417d830> 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 0x000000002417d830> 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 0x000000002417d830> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000025ab5b60> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000000d67bfa0> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x00000000299c1d38>, <W_TypeObject 'GenericAlias' at 0x17b52480>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x17b108e0> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x17b108e0> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x17b108e0> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x17b108e0> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xb7dcf10>> w_obj = <W_TypeObject 'ellipsis' at 0x17b108e0> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x17b108e0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xb7dcf10>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x17b108e0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xb7dcf10>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xb7dcf10>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xb7dcf10>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _____________ ERROR at setup of AppTestRecompiler.test_loader_spec _____________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000001d2f8b60>, 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_loader_spec'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_loader_spec'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_loader_spec'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_loader_spec'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_loader_spec'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_loader_spec'>} 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_loader_spec'>, '__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 0x0000000020178d90> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...oader_spec'>, '__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 0x00000000059d59a0> 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 0x00000000059d59a0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...oader_spec'>, '__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_loader_spec'>, '__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_loader_spec'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000020e111a0> key = (((True, True, True, 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 0x0000000020e111a0> 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 0x0000000020e111a0> 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 0x0000000020e111a0> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x00000000055d3060> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000214e24b8> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000020e11718>, <W_TypeObject 'GenericAlias' at 0x1aa92560>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x19c7f9b8> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x19c7f9b8> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x19c7f9b8> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x19c7f9b8> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x9823cd0>> w_obj = <W_TypeObject 'ellipsis' at 0x19c7f9b8> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x19c7f9b8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x9823cd0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x19c7f9b8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x9823cd0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x9823cd0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x9823cd0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _______________ ERROR at setup of AppTestRecompiler.test_release _______________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000024f67268>, 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_release'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_release'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_release'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_release'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_release'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_release'>} 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_release'>, '__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 0x00000000241b7128> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...st_release'>, '__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 0x000000001dbcf0e0> 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 0x000000001dbcf0e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...st_release'>, '__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_release'>, '__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_release'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000002a593d70> key = (((True, True, True, 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 0x000000002a593d70> 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 0x000000002a593d70> 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 0x000000002a593d70> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000001dc0a560> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000001c6e2de8> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000002a702330>, <W_TypeObject 'GenericAlias' at 0x277e0e20>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x220c54e8> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x220c54e8> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x220c54e8> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x220c54e8> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13e9adb0>> w_obj = <W_TypeObject 'ellipsis' at 0x220c54e8> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x220c54e8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13e9adb0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x220c54e8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13e9adb0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13e9adb0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x13e9adb0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ________ ERROR at setup of AppTestRecompiler.test_release_new_allocator ________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000023f72458>, 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_release_new_allocator'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_release_new_allocator'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_release_new_allocator'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_release_new_allocator'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_release_new_allocator'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_release_new_allocator'>} 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_release_new_allocator'>, '__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 0x000000001bddbf10> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._allocator'>, '__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 0x000000002772b020> 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 0x000000002772b020> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._allocator'>, '__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_release_new_allocator'>, '__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_release_new_allocator'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000001d207be8> key = (((True, True, True, 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 0x000000001d207be8> 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 0x000000001d207be8> 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 0x000000001d207be8> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000027774320> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000028650918> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000001d1a01a8>, <W_TypeObject 'GenericAlias' at 0x23415f30>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2c49bd70> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2c49bd70> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2c49bd70> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2c49bd70> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x9900a90>> w_obj = <W_TypeObject 'ellipsis' at 0x2c49bd70> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x2c49bd70>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x9900a90>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x2c49bd70> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x9900a90>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x9900a90>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x9900a90>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError __ ERROR at setup of AppTestRecompiler.test_struct_with_func_with_struct_arg ___ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000024d55718>, 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_struct_with_func_with_struct_ar...l__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_struct_with_func_with_struct_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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_struct_with_func_with_struct_ar...l__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_struct_with_func_with_struct_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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_struct_with_func_with_struct_ar...l__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_struct_with_func_with_struct_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_struct_with_func_with_struct_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 0x0000000017070750> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...struct_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 0x0000000026fdc120> 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 0x0000000026fdc120> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...struct_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_struct_with_func_with_struct_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_struct_with_func_with_struct_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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x000000002c485a98> key = (((True, True, True, 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 0x000000002c485a98> 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 0x000000002c485a98> 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 0x000000002c485a98> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000026fdd6a0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000002ad36410> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000028cc00c8>, <W_TypeObject 'GenericAlias' at 0x223ee1a8>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1cf13980> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1cf13980> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1cf13980> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x1cf13980> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xaf0f640>> w_obj = <W_TypeObject 'ellipsis' at 0x1cf13980> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x1cf13980>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xaf0f640>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x1cf13980> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xaf0f640>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xaf0f640>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xaf0f640>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ____ ERROR at setup of AppTestRecompiler.test_call_function_offset_in_bytes ____ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000001f47f970>, 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_call_function_offset_in_bytes'>...call__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_call_function_offset_in_bytes'>} 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 0x00007f6da0e916a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_call_function_offset_in_bytes'>...call__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_call_function_offset_in_bytes'>} 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 0x00007f6da0f6eba0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000001739760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000017397a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_call_function_offset_in_bytes'>...call__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_call_function_offset_in_bytes'>} 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_call_function_offset_in_bytes'>, '__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 0x000000001638ca48> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_in_bytes'>, '__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 0x0000000017f948e0> 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 0x0000000017f948e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_in_bytes'>, '__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_call_function_offset_in_bytes'>, '__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_call_function_offset_in_bytes'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'usemodules': ['_cffi_backend', 'imp', 'cpyext', 'struct']} config = <rpython.config.config.Config object at 0x0000000029efd018> key = (((True, True, True, 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 0x0000000029efd018> 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 0x0000000029efd018> 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 0x0000000029efd018> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000017f95b20> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000264fff30> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672e40>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6da1672e80>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6da1672ea0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000006ee8e20>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000029efd590>, <W_TypeObject 'GenericAlias' at 0x2138a950>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2138fc20> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2138fc20> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2138fc20> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2138fc20> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1c3662c0>> w_obj = <W_TypeObject 'ellipsis' at 0x2138fc20> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x2138fc20>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1c3662c0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x2138fc20> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1c3662c0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1c3662c0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1c3662c0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ============== 335 passed, 9 skipped, 124 error in 632.65 seconds ============== ++ 02:42:29 starting module/cpyext/test/test_arraymodule.py [46 started in total] __ module/cpyext/test/test_api.py [43 done in total, somefailed=True] _________ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 4 items module/cpyext/test/test_api.py EE.. ==================================== ERRORS ==================================== ______________ ERROR at setup of TestConversion.test_conversions _______________ item = <Function 'test_conversions'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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:481: in __init__ self.initialize() objspace/std/objspace.py:118: in initialize self.setup_builtin_modules() interpreter/baseobjspace.py:739: in setup_builtin_modules self.fromcache(State).build_api() module/cpyext/state.py:128: in build_api self.api_lib = str(api.build_bridge(self.space)) module/cpyext/api.py:1468: in build_bridge builder.attach_all(space) module/cpyext/api.py:1535: in attach_all attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1497: in attach_recursively make_ref(space, w_type)) module/cpyext/pyobject.py:510: in make_ref return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:483: in get_pyobj_and_incref pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: in as_pyobj py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:326: in create_ref track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:375: in track_reference w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:132: in _cpyext_attach_pyobj rawrefcount.create_link_pypy(self, py_obj) ../rpython/rlib/rawrefcount.py:187: in create_link_pypy assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:102: in _ob_link_get return ob.c_ob_pypy_link _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1679a7e0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ________________ ERROR at setup of TestConversion.test_typedef _________________ item = <Function 'test_typedef'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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:481: in __init__ self.initialize() objspace/std/objspace.py:118: in initialize self.setup_builtin_modules() interpreter/baseobjspace.py:739: in setup_builtin_modules self.fromcache(State).build_api() module/cpyext/state.py:128: in build_api self.api_lib = str(api.build_bridge(self.space)) module/cpyext/api.py:1468: in build_bridge builder.attach_all(space) module/cpyext/api.py:1535: in attach_all attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1497: in attach_recursively make_ref(space, w_type)) module/cpyext/pyobject.py:510: in make_ref return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:483: in get_pyobj_and_incref pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: in as_pyobj py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:326: in create_ref track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:375: in track_reference w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:132: in _cpyext_attach_pyobj rawrefcount.create_link_pypy(self, py_obj) ../rpython/rlib/rawrefcount.py:187: in create_link_pypy assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:102: in _ob_link_get return ob.c_ob_pypy_link _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x15b65820>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ====================== 2 passed, 2 error in 11.07 seconds ====================== ++ 02:42:36 starting module/cpyext/test/test_async_iter.py [47 started in total] __ module/array/test [44 done in total, somefailed=False] _____________________ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 64 items module/array/test/apptest_array.py ... module/array/test/test_array.py .....................s..................s................... module/array/test/test_ztranslation.py . ==================== 62 passed, 2 skipped in 84.86 seconds ===================== ++ 02:42:42 starting module/cpyext/test/test_boolobject.py [48 started in total] __ module/bz2/test [45 done in total, somefailed=False] _______________________ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 53 items module/bz2/test/apptest_bz2_compdecomp.py .s... module/bz2/test/test_bz2_compdecomp.py ..s............. module/bz2/test/test_bz2_file.py ............................ module/bz2/test/test_interpbz2.py ... module/bz2/test/test_large.py s ==================== 50 passed, 3 skipped in 71.79 seconds ===================== ++ 02:42:59 starting module/cpyext/test/test_borrow.py [49 started in total] __ module/cpyext/test/test_async_iter.py [46 done in total, somefailed=True] __ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 3 items module/cpyext/test/test_async_iter.py EEE ==================================== ERRORS ==================================== _______________ ERROR at setup of AppTestAsyncIter.test_asyncgen _______________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000000adfa278>, 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_asyncgen'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_asyncgen'>} 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 0x00007f9414513638> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000a8c62a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000246f7e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000246f820>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_asyncgen'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_asyncgen'>} 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 0x000000000a8c62a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000246f7e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000246f820>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_asyncgen'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_asyncgen'>} 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_asyncgen'>, '__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 0x000000000ade99e8> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_asyncgen'>, '__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 0x000000000ae022e0> 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 0x000000000ae022e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_asyncgen'>, '__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_asyncgen'>, '__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_asyncgen'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x000000000ae08a30> key = (((True, True, True, 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 0x000000000ae08a30> 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 0x000000000ae08a30> 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 0x000000000ae08a30> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000000b3fa820> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000000b84dd70> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f9414c72e60>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f9414c72ea0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f9414c72ec0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000000591ecd0>, W_BoolObject(True), W_BoolObject(False), <p...70>, <pypy.interpreter.special.Ellipsis object at 0x000000000ae08fa8>, <W_TypeObject 'GenericAlias' at 0x973b440>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x8d13718> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x8d13718> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x8d13718> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x8d13718> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xa11c7d0>> w_obj = <W_TypeObject 'ellipsis' at 0x8d13718> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x8d13718>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xa11c7d0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x8d13718> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xa11c7d0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xa11c7d0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xa11c7d0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ________ ERROR at setup of AppTestAsyncIter.test_async_gen_exception_04 ________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000000d2e63e0>, 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_async_gen_exception_04'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_async_gen_exception_04'>} 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 0x00007f9414513638> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000a8c62a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000246f7e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000246f820>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_async_gen_exception_04'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_async_gen_exception_04'>} 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 0x000000000a8c62a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000246f7e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000246f820>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_async_gen_exception_04'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_async_gen_exception_04'>} 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_async_gen_exception_04'>, '__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 0x000000000b458368> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ception_04'>, '__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 0x000000000d3043a0> 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 0x000000000d3043a0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ception_04'>, '__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_async_gen_exception_04'>, '__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_async_gen_exception_04'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x000000000d32e250> key = (((True, True, True, 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 0x000000000d32e250> 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 0x000000000d32e250> 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 0x000000000d32e250> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000000d5a48a0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000000d65fa98> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f9414c72e60>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f9414c72ea0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f9414c72ec0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000000591ecd0>, W_BoolObject(True), W_BoolObject(False), <p...90>, <pypy.interpreter.special.Ellipsis object at 0x000000000d32e7c8>, <W_TypeObject 'GenericAlias' at 0xdb01018>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0xdc570f8> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0xdc570f8> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0xdc570f8> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0xdc570f8> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x9301ed0>> w_obj = <W_TypeObject 'ellipsis' at 0xdc570f8> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0xdc570f8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x9301ed0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0xdc570f8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x9301ed0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x9301ed0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x9301ed0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _____________ ERROR at setup of AppTestAsyncIter.test_coro_retval ______________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000003cab9e8>, 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_coro_retval'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_coro_retval'>} 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 0x00007f9414513638> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000a8c62a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000246f7e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000246f820>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_coro_retval'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_coro_retval'>} 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 0x000000000a8c62a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000246f7e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000246f820>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_coro_retval'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_coro_retval'>} 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_coro_retval'>, '__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 0x0000000007b48ea8> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...oro_retval'>, '__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 0x000000000c1f5fa0> 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 0x000000000c1f5fa0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...oro_retval'>, '__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_coro_retval'>, '__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_coro_retval'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x000000000d8d0fa8> key = (((True, True, True, 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 0x000000000d8d0fa8> 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 0x000000000d8d0fa8> 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 0x000000000d8d0fa8> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000000cafce20> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000000dc492f0> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f9414c72e60>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f9414c72ea0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f9414c72ec0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000000591ecd0>, W_BoolObject(True), W_BoolObject(False), <p...e8>, <pypy.interpreter.special.Ellipsis object at 0x000000000d8d1520>, <W_TypeObject 'GenericAlias' at 0xcfc2d78>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0xca82918> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0xca82918> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0xca82918> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0xca82918> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fe4760>> w_obj = <W_TypeObject 'ellipsis' at 0xca82918> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0xca82918>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fe4760>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0xca82918> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fe4760>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fe4760>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fe4760>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError =========================== 3 error in 15.58 seconds =========================== ++ 02:43:04 starting module/cpyext/test/test_buffer.py [50 started in total] __ module/cpyext/test/test_boolobject.py [47 done in total, somefailed=True] __ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 4 items module/cpyext/test/test_boolobject.py EEEE ==================================== ERRORS ==================================== ________________ ERROR at setup of TestBoolObject.test_fromlong ________________ item = <Function 'test_fromlong'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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:481: in __init__ self.initialize() objspace/std/objspace.py:118: in initialize self.setup_builtin_modules() interpreter/baseobjspace.py:739: in setup_builtin_modules self.fromcache(State).build_api() module/cpyext/state.py:128: in build_api self.api_lib = str(api.build_bridge(self.space)) module/cpyext/api.py:1468: in build_bridge builder.attach_all(space) module/cpyext/api.py:1535: in attach_all attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1497: in attach_recursively make_ref(space, w_type)) module/cpyext/pyobject.py:510: in make_ref return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:483: in get_pyobj_and_incref pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: in as_pyobj py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:326: in create_ref track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:375: in track_reference w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:132: in _cpyext_attach_pyobj rawrefcount.create_link_pypy(self, py_obj) ../rpython/rlib/rawrefcount.py:187: in create_link_pypy assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:102: in _ob_link_get return ob.c_ob_pypy_link _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x344e7c40>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _______________ ERROR at setup of AppTestBoolMacros.test_macros ________________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x00000000374604d0>, 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_macros'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_macros'>} 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 0x00007faecd595280> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000035070b20>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cb1f7a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cb1f7e0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_macros'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_macros'>} 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 0x0000000035070b20>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cb1f7a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cb1f7e0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_macros'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_macros'>} 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_macros'>, '__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 0x0000000035bd0520> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...est_macros'>, '__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 0x000000003748fb60> 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 0x000000003748fb60> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...est_macros'>, '__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_macros'>, '__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_macros'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x00000000374ae528> key = (((True, True, True, 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 0x00000000374ae528> 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 0x00000000374ae528> 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 0x00000000374ae528> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x00000000376efa60> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000037794ec8> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7faecdc70e80>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7faecdc70ec0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7faecdc70ee0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000002e3d9718>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x00000000374aeaa0>, <W_TypeObject 'GenericAlias' at 0x31bd13d0>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2f6f67c8> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2f6f67c8> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2f6f67c8> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2f6f67c8> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x363db740>> w_obj = <W_TypeObject 'ellipsis' at 0x2f6f67c8> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x2f6f67c8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x363db740>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x2f6f67c8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x363db740>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x363db740>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x363db740>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ________________ ERROR at setup of AppTestBoolMacros.test_toint ________________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000031bfd100>, 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_toint'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_toint'>} 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 0x00007faecd595280> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000035070b20>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cb1f7a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cb1f7e0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_toint'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_toint'>} 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 0x0000000035070b20>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cb1f7a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cb1f7e0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_toint'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_toint'>} 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_toint'>, '__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 0x0000000032a18a48> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...test_toint'>, '__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 0x00000000374e1e20> 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 0x00000000374e1e20> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...test_toint'>, '__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_toint'>, '__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_toint'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x00000000368759b8> key = (((True, True, True, 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 0x00000000368759b8> 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 0x00000000368759b8> 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 0x00000000368759b8> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x00000000377288e0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000036a64b80> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7faecdc70e80>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7faecdc70ec0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7faecdc70ee0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000002e3d9718>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000036875f30>, <W_TypeObject 'GenericAlias' at 0x365fa058>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x373251d8> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x373251d8> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x373251d8> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x373251d8> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x32ff7000>> w_obj = <W_TypeObject 'ellipsis' at 0x373251d8> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x373251d8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x32ff7000>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x373251d8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x32ff7000>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x32ff7000>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x32ff7000>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ________________ ERROR at setup of AppTestBoolMacros.test_check ________________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000035e642f0>, 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_check'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_check'>} 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 0x00007faecd595280> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000035070b20>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cb1f7a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cb1f7e0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_check'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_check'>} 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 0x0000000035070b20>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cb1f7a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cb1f7e0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_check'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_check'>} 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_check'>, '__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 0x0000000035c700c0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...test_check'>, '__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 0x00000000390e79e0> 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 0x00000000390e79e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...test_check'>, '__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_check'>, '__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_check'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x00000000390eb248> key = (((True, True, True, 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 0x00000000390eb248> 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 0x00000000390eb248> 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 0x00000000390eb248> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x00000000379e5420> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000030962f00> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7faecdc70e80>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7faecdc70ec0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7faecdc70ee0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000002e3d9718>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x00000000390eb7c0>, <W_TypeObject 'GenericAlias' at 0x326c4090>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x32782800> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x32782800> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x32782800> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x32782800> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x33ea9680>> w_obj = <W_TypeObject 'ellipsis' at 0x32782800> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x32782800>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x33ea9680>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x32782800> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x33ea9680>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x33ea9680>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x33ea9680>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError =========================== 4 error in 19.30 seconds =========================== ++ 02:43:14 starting module/cpyext/test/test_bytearrayobject.py [51 started in total] __ module/cpyext/test/test_borrow.py [48 done in total, somefailed=True] ______ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 3 items module/cpyext/test/test_borrow.py EEE ==================================== ERRORS ==================================== _____________ ERROR at setup of AppTestBorrow.test_tuple_borrowing _____________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x00000000347fbb50>, 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_tuple_borrowing'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_tuple_borrowing'>} 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 0x00007f19663136e0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000034ffc1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cf5b7a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cf5b7e0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_tuple_borrowing'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_tuple_borrowing'>} 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 0x0000000034ffc1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cf5b7a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cf5b7e0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_tuple_borrowing'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_tuple_borrowing'>} 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_tuple_borrowing'>, '__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 0x00000000347d09a8> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._borrowing'>, '__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 0x000000003481df60> 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 0x000000003481df60> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._borrowing'>, '__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_tuple_borrowing'>, '__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_tuple_borrowing'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x00000000347e4020> key = (((True, True, True, 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 0x00000000347e4020> 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 0x00000000347e4020> 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 0x00000000347e4020> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000035b11ba0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000035e47520> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f1966a72e80>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f1966a72ec0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f1966a72ee0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000002f7611a0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x00000000347e4598>, <W_TypeObject 'GenericAlias' at 0x369ada28>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x31fafc20> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x31fafc20> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x31fafc20> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x31fafc20> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x33c475d0>> w_obj = <W_TypeObject 'ellipsis' at 0x31fafc20> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x31fafc20>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x33c475d0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x31fafc20> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x33c475d0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x33c475d0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x33c475d0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _____________ ERROR at setup of AppTestBorrow.test_borrow_destroy ______________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x00000000375c1010>, 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_borrow_destroy'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_borrow_destroy'>} 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 0x00007f19663136e0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000034ffc1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cf5b7a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cf5b7e0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_borrow_destroy'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_borrow_destroy'>} 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 0x0000000034ffc1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cf5b7a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cf5b7e0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_borrow_destroy'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_borrow_destroy'>} 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_borrow_destroy'>, '__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 0x00000000348285c0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ow_destroy'>, '__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 0x00000000369f87e0> 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 0x00000000369f87e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ow_destroy'>, '__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_borrow_destroy'>, '__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_borrow_destroy'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x00000000375e9328> key = (((True, True, True, 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 0x00000000375e9328> 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 0x00000000375e9328> 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 0x00000000375e9328> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000003776f2e0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000037813e88> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f1966a72e80>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f1966a72ec0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f1966a72ee0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000002f7611a0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x00000000375e9a60>, <W_TypeObject 'GenericAlias' at 0x37bcb638>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x37cb0090> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x37cb0090> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x37cb0090> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x37cb0090> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3226bdb0>> w_obj = <W_TypeObject 'ellipsis' at 0x37cb0090> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x37cb0090>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3226bdb0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x37cb0090> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3226bdb0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3226bdb0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3226bdb0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ______________ ERROR at setup of AppTestBorrow.test_double_borrow ______________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000034e1f358>, 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_double_borrow'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_double_borrow'>} 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 0x00007f19663136e0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000034ffc1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cf5b7a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cf5b7e0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_double_borrow'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_double_borrow'>} 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 0x0000000034ffc1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cf5b7a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cf5b7e0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_double_borrow'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_double_borrow'>} 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_double_borrow'>, '__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 0x0000000036f10048> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ble_borrow'>, '__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 0x00000000310867e0> 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 0x00000000310867e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ble_borrow'>, '__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_double_borrow'>, '__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_double_borrow'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x0000000033c0ebf0> key = (((True, True, True, 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 0x0000000033c0ebf0> 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 0x0000000033c0ebf0> 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 0x0000000033c0ebf0> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000032dcef60> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000034d51830> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f1966a72e80>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f1966a72ec0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f1966a72ee0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000002f7611a0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000033c1a2f8>, <W_TypeObject 'GenericAlias' at 0x34b3ea30>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3585c838> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3585c838> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3585c838> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3585c838> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x31e50f70>> w_obj = <W_TypeObject 'ellipsis' at 0x3585c838> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x3585c838>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x31e50f70>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x3585c838> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x31e50f70>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x31e50f70>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x31e50f70>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError =========================== 3 error in 14.88 seconds =========================== ++ 02:43:27 starting module/cpyext/test/test_bytesobject.py [52 started in total] __ module/cpyext/test/test_buffer.py [49 done in total, somefailed=True] ______ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 6 items module/cpyext/test/test_buffer.py EEEEEE ==================================== ERRORS ==================================== ____________ ERROR at setup of AppTestBuffer.test_size_from_format _____________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000049031448>, 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_size_from_format'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_size_from_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 0x00007fe652091638> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000048acd4e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000004080b760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000004080b7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_size_from_format'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_size_from_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 0x0000000048acd4e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000004080b760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000004080b7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_size_from_format'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_size_from_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_size_from_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 0x000000004905fb00> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...rom_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 0x000000004906c3a0> 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 0x000000004906c3a0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...rom_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_size_from_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_size_from_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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x000000004905bd00> key = (((True, True, True, 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 0x000000004905bd00> 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 0x000000004905bd00> 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 0x000000004905bd00> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x00000000495d4da0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004997b5c8> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fe652872e60>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7fe652872ea0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fe652872ec0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000042149fa0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x00000000490762c0>, <W_TypeObject 'GenericAlias' at 0x486924b8>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x48380640> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x48380640> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x48380640> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x48380640> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x432156a0>> w_obj = <W_TypeObject 'ellipsis' at 0x48380640> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x48380640>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x432156a0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x48380640> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x432156a0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x432156a0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x432156a0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ______________ ERROR at setup of AppTestBuffer.test_AsWriteBuffer ______________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000004b690110>, 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_AsWriteBuffer'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_AsWriteBuffer'>} 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 0x00007fe652091638> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000048acd4e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000004080b760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000004080b7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_AsWriteBuffer'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_AsWriteBuffer'>} 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 0x0000000048acd4e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000004080b760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000004080b7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_AsWriteBuffer'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_AsWriteBuffer'>} 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_AsWriteBuffer'>, '__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 0x000000004b6bca98> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...riteBuffer'>, '__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 0x000000004b663420> 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 0x000000004b663420> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...riteBuffer'>, '__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_AsWriteBuffer'>, '__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_AsWriteBuffer'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x000000004b6c0918> key = (((True, True, True, 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 0x000000004b6c0918> 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 0x000000004b6c0918> 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 0x000000004b6c0918> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000004b95c0e0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004ba38608> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fe652872e60>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7fe652872ea0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fe652872ec0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000042149fa0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000004b6c0e90>, <W_TypeObject 'GenericAlias' at 0x44b08c28>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x45a83fa0> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x45a83fa0> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x45a83fa0> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x45a83fa0> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x46e56a80>> w_obj = <W_TypeObject 'ellipsis' at 0x45a83fa0> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x45a83fa0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x46e56a80>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x45a83fa0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x46e56a80>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x46e56a80>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x46e56a80>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _______________ ERROR at setup of AppTestBuffer.test_mmap_buffer _______________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000004879e110>, 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_mmap_buffer'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_mmap_buffer'>} 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 0x00007fe652091638> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000048acd4e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000004080b760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000004080b7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_mmap_buffer'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_mmap_buffer'>} 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 0x0000000048acd4e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000004080b760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000004080b7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_mmap_buffer'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_mmap_buffer'>} 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_mmap_buffer'>, '__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 0x0000000046d1d380> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...map_buffer'>, '__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 0x0000000049f90160> 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 0x0000000049f90160> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...map_buffer'>, '__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_mmap_buffer'>, '__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_mmap_buffer'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x000000004b3f7130> key = (((True, True, True, 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 0x000000004b3f7130> 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 0x000000004b3f7130> 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 0x000000004b3f7130> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000004b1a2760> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004b1bff68> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fe652872e60>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7fe652872ea0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fe652872ec0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000042149fa0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000004b3f76a8>, <W_TypeObject 'GenericAlias' at 0x4b50cd40>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4b56c1e0> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4b56c1e0> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4b56c1e0> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4b56c1e0> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x46f25860>> w_obj = <W_TypeObject 'ellipsis' at 0x4b56c1e0> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x4b56c1e0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x46f25860>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x4b56c1e0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x46f25860>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x46f25860>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x46f25860>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ________________ ERROR at setup of AppTestBuffer.test_applevel _________________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000004bd08278>, 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_applevel'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_applevel'>} 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 0x00007fe652091638> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000048acd4e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000004080b760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000004080b7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_applevel'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_applevel'>} 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 0x0000000048acd4e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000004080b760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000004080b7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_applevel'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_applevel'>} 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_applevel'>, '__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 0x000000004ce4d858> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_applevel'>, '__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 0x000000004ce09260> 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 0x000000004ce09260> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_applevel'>, '__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_applevel'>, '__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_applevel'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x000000004c4b8058> key = (((True, True, True, 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 0x000000004c4b8058> 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 0x000000004c4b8058> 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 0x000000004c4b8058> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000040bbaaa0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000040c8fa98> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fe652872e60>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7fe652872ea0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fe652872ec0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000042149fa0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000004c4b85d0>, <W_TypeObject 'GenericAlias' at 0x46155e88>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x466badb0> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x466badb0> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x466badb0> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x466badb0> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x430896a0>> w_obj = <W_TypeObject 'ellipsis' at 0x466badb0> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x466badb0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x430896a0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x466badb0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x430896a0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x430896a0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x430896a0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ________________ ERROR at setup of AppTestBuffer.test_argparse _________________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000045ea33d0>, 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_argparse'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_argparse'>} 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 0x00007fe652091638> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000048acd4e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000004080b760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000004080b7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_argparse'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_argparse'>} 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 0x0000000048acd4e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000004080b760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000004080b7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_argparse'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_argparse'>} 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_argparse'>, '__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 0x0000000045ede098> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_argparse'>, '__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 0x000000004b492ee0> 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 0x000000004b492ee0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_argparse'>, '__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_argparse'>, '__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_argparse'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x0000000048a26608> key = (((True, True, True, 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 0x0000000048a26608> 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 0x0000000048a26608> 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 0x0000000048a26608> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000004b5388a0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004a8dd6a8> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fe652872e60>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7fe652872ea0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fe652872ec0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000042149fa0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000048a26f00>, <W_TypeObject 'GenericAlias' at 0x49e386b0>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4a4310f8> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4a4310f8> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4a4310f8> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4a4310f8> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x48029250>> w_obj = <W_TypeObject 'ellipsis' at 0x4a4310f8> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x4a4310f8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x48029250>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x4a4310f8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x48029250>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x48029250>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x48029250>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _ ERROR at setup of AppTestBuffer.test_bytearray_release_buffer_unlocks_resize _ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000004d6fd448>, 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_bytearray_release_buffer_unlock..._MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_bytearray_release_buffer_unlocks_resize'>} 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 0x00007fe652091638> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000048acd4e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000004080b760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000004080b7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_bytearray_release_buffer_unlock..._MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_bytearray_release_buffer_unlocks_resize'>} 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 0x0000000048acd4e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000004080b760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000004080b7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_bytearray_release_buffer_unlock..._MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_bytearray_release_buffer_unlocks_resize'>} 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_bytearray_release_buffer_unlocks_resize'>, '__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 0x00000000496d05e8> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...cks_resize'>, '__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 0x000000004e01eca0> 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 0x000000004e01eca0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...cks_resize'>, '__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_bytearray_release_buffer_unlocks_resize'>, '__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_bytearray_release_buffer_unlocks_resize'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x000000004e026448> key = (((True, True, True, 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 0x000000004e026448> 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 0x000000004e026448> 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 0x000000004e026448> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000004e162c20> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000004e34b3d0> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fe652872e60>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7fe652872ea0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fe652872ec0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000042149fa0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000004e027f30>, <W_TypeObject 'GenericAlias' at 0x463deaa0>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x45818870> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x45818870> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x45818870> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x45818870> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x485137d0>> w_obj = <W_TypeObject 'ellipsis' at 0x45818870> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x45818870>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x485137d0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x45818870> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x485137d0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x485137d0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x485137d0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError =========================== 6 error in 27.34 seconds =========================== ++ 02:43:42 starting module/cpyext/test/test_capsule.py [53 started in total] __ module/cpyext/test/test_bytearrayobject.py [50 done in total, somefailed=True] ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 6 items module/cpyext/test/test_bytearrayobject.py EEEEEE ==================================== ERRORS ==================================== _______________ ERROR at setup of AppTestStringObject.test_basic _______________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000000752d538>, 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_basic'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_basic'>} 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 0x00007f655e195600> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000078bf2e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000000e29720>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000000e29760>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_basic'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_basic'>} 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 0x00000000078bf2e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000000e29720>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000000e29760>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_basic'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_basic'>} 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_basic'>, '__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 0x0000000007559d30> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...test_basic'>, '__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 0x00000000075632e0> 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 0x00000000075632e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...test_basic'>, '__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_basic'>, '__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_basic'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x00000000075764f0> key = (((True, True, True, 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 0x00000000075764f0> 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 0x00000000075764f0> 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 0x00000000075764f0> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000009a8ab20> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000009e87830> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f655e870e60>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f655e870ea0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f655e870ec0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000000026c41a8>, W_BoolObject(True), W_BoolObject(False), <p...30>, <pypy.interpreter.special.Ellipsis object at 0x0000000007576a68>, <W_TypeObject 'GenericAlias' at 0x4231168>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x500dd70> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x500dd70> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x500dd70> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x500dd70> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1f32340>> w_obj = <W_TypeObject 'ellipsis' at 0x500dd70> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x500dd70>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1f32340>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x500dd70> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1f32340>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1f32340>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1f32340>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _______ ERROR at setup of AppTestStringObject.test_bytearray_buffer_init _______ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000000b3fc728>, 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_bytearray_buffer_init'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_bytearray_buffer_init'>} 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 0x00007f655e195600> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000078bf2e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000000e29720>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000000e29760>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_bytearray_buffer_init'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_bytearray_buffer_init'>} 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 0x00000000078bf2e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000000e29720>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000000e29760>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_bytearray_buffer_init'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_bytearray_buffer_init'>} 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_bytearray_buffer_init'>, '__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 0x00000000094306b0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...uffer_init'>, '__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 0x000000000b433fa0> 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 0x000000000b433fa0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...uffer_init'>, '__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_bytearray_buffer_init'>, '__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_bytearray_buffer_init'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x000000000b44b948> key = (((True, True, True, 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 0x000000000b44b948> 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 0x000000000b44b948> 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 0x000000000b44b948> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000000b6ac120> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000000b766330> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f655e870e60>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f655e870ea0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f655e870ec0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000000026c41a8>, W_BoolObject(True), W_BoolObject(False), <p...88>, <pypy.interpreter.special.Ellipsis object at 0x000000000b44bec0>, <W_TypeObject 'GenericAlias' at 0xbb85590>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0xbc291a0> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0xbc291a0> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0xbc291a0> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0xbc291a0> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x53bb5b0>> w_obj = <W_TypeObject 'ellipsis' at 0xbc291a0> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0xbc291a0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x53bb5b0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0xbc291a0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x53bb5b0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x53bb5b0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x53bb5b0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _________ ERROR at setup of AppTestStringObject.test_bytearray_mutable _________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000004ebdda8>, 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_bytearray_mutable'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_bytearray_mutable'>} 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 0x00007f655e195600> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000078bf2e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000000e29720>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000000e29760>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_bytearray_mutable'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_bytearray_mutable'>} 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 0x00000000078bf2e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000000e29720>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000000e29760>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_bytearray_mutable'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_bytearray_mutable'>} 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_bytearray_mutable'>, '__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 0x0000000005f8a4f8> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ay_mutable'>, '__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 0x00000000098896a0> 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 0x00000000098896a0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ay_mutable'>, '__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_bytearray_mutable'>, '__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_bytearray_mutable'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x0000000009952678> key = (((True, True, True, 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 0x0000000009952678> 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 0x0000000009952678> 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 0x0000000009952678> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000009bafb60> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000009eeb520> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f655e870e60>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f655e870ea0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f655e870ec0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000000026c41a8>, W_BoolObject(True), W_BoolObject(False), <p...b8>, <pypy.interpreter.special.Ellipsis object at 0x0000000009952bf0>, <W_TypeObject 'GenericAlias' at 0xb8c7248>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0xb981c90> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0xb981c90> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0xb981c90> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0xb981c90> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x8489ea0>> w_obj = <W_TypeObject 'ellipsis' at 0xb981c90> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0xb981c90>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x8489ea0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0xb981c90> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x8489ea0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x8489ea0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x8489ea0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ____________ ERROR at setup of AppTestStringObject.test_AsByteArray ____________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x00000000099f0db8>, 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_AsByteArray'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_AsByteArray'>} 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 0x00007f655e195600> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000078bf2e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000000e29720>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000000e29760>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_AsByteArray'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_AsByteArray'>} 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 0x00000000078bf2e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000000e29720>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000000e29760>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_AsByteArray'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_AsByteArray'>} 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_AsByteArray'>, '__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 0x0000000009a709d0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...sByteArray'>, '__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 0x000000000d22c2e0> 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 0x000000000d22c2e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...sByteArray'>, '__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_AsByteArray'>, '__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_AsByteArray'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x000000000d22e218> key = (((True, True, True, 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 0x000000000d22e218> 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 0x000000000d22e218> 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 0x000000000d22e218> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000000d2f4a20> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000000d382678> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f655e870e60>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f655e870ea0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f655e870ec0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000000026c41a8>, W_BoolObject(True), W_BoolObject(False), <p...58>, <pypy.interpreter.special.Ellipsis object at 0x000000000d22e790>, <W_TypeObject 'GenericAlias' at 0xd703910>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0xd7912f0> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0xd7912f0> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0xd7912f0> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0xd7912f0> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xa97e2b0>> w_obj = <W_TypeObject 'ellipsis' at 0xd7912f0> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0xd7912f0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xa97e2b0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0xd7912f0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xa97e2b0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xa97e2b0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xa97e2b0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ___________ ERROR at setup of AppTestStringObject.test_manipulations ___________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000008a3bc40>, 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_manipulations'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_manipulations'>} 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 0x00007f655e195600> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000078bf2e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000000e29720>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000000e29760>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_manipulations'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_manipulations'>} 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 0x00000000078bf2e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000000e29720>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000000e29760>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_manipulations'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_manipulations'>} 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_manipulations'>, '__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 0x000000000506eb38> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ipulations'>, '__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 0x000000000a4bc920> 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 0x000000000a4bc920> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ipulations'>, '__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_manipulations'>, '__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_manipulations'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x000000000a72a8e0> key = (((True, True, True, 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 0x000000000a72a8e0> 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 0x000000000a72a8e0> 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 0x000000000a72a8e0> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000000a5fe0a0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000000b43bf68> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f655e870e60>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f655e870ea0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f655e870ec0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000000026c41a8>, W_BoolObject(True), W_BoolObject(False), <p...20>, <pypy.interpreter.special.Ellipsis object at 0x000000000a72ae58>, <W_TypeObject 'GenericAlias' at 0xd2ee020>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0xd450090> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0xd450090> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0xd450090> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0xd450090> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x5b3ff10>> w_obj = <W_TypeObject 'ellipsis' at 0xd450090> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0xd450090>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x5b3ff10>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0xd450090> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x5b3ff10>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x5b3ff10>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x5b3ff10>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _________ ERROR at setup of AppTestStringObject.test_bytearray_resize __________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000000615bbc8>, 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_bytearray_resize'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_bytearray_resize'>} 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 0x00007f655e195600> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000078bf2e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000000e29720>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000000e29760>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_bytearray_resize'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_bytearray_resize'>} 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 0x00000000078bf2e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000000e29720>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000000e29760>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_bytearray_resize'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_bytearray_resize'>} 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_bytearray_resize'>, '__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 0x000000000826a1b0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ray_resize'>, '__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 0x000000000afae3a0> 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 0x000000000afae3a0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ray_resize'>, '__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_bytearray_resize'>, '__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_bytearray_resize'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x000000000afad018> key = (((True, True, True, 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 0x000000000afad018> 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 0x000000000afad018> 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 0x000000000afad018> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000000c1c9560> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000000c262608> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f655e870e60>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f655e870ea0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f655e870ec0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000000026c41a8>, W_BoolObject(True), W_BoolObject(False), <p...58>, <pypy.interpreter.special.Ellipsis object at 0x000000000afad590>, <W_TypeObject 'GenericAlias' at 0xc5142f8>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0xcb40870> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0xcb40870> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0xcb40870> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0xcb40870> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xa7fefa0>> w_obj = <W_TypeObject 'ellipsis' at 0xcb40870> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0xcb40870>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xa7fefa0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0xcb40870> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xa7fefa0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xa7fefa0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0xa7fefa0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError =========================== 6 error in 27.29 seconds =========================== ++ 02:43:52 starting module/cpyext/test/test_cell.py [54 started in total] __ module/cpyext/test/test_arraymodule.py [51 done in total, somefailed=True] _ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 18 items module/cpyext/test/test_arraymodule.py EEEEEEEEEEEEEEEEEE ==================================== ERRORS ==================================== _______________ ERROR at setup of AppTestArrayModule.test_basic ________________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000003564ff10>, 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_basic'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_basic'>} 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 0x00007f91f8913670> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000350ef1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cd8d760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cd8d7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_basic'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_basic'>} 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 0x00000000350ef1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cd8d760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cd8d7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_basic'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_basic'>} 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_basic'>, '__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 0x000000003567b218> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...test_basic'>, '__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 0x000000003569b3e0> 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 0x000000003569b3e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...test_basic'>, '__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_basic'>, '__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_basic'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x00000000356a5980> key = (((True, True, True, 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 0x00000000356a5980> 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 0x00000000356a5980> 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 0x00000000356a5980> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000035ca07a0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000003604ab80> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f91fd41fe60>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f91fd41fea0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f91fd41fec0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000030c31440>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x00000000356a5ef8>, <W_TypeObject 'GenericAlias' at 0x349cee58>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x33b99520> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x33b99520> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x33b99520> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x33b99520> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x348cbb40>> w_obj = <W_TypeObject 'ellipsis' at 0x33b99520> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x33b99520>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x348cbb40>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x33b99520> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x348cbb40>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x348cbb40>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x348cbb40>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ________________ ERROR at setup of AppTestArrayModule.test_iter ________________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000003774bda8>, 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'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_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 0x00007f91f8913670> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000350ef1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cd8d760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cd8d7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_iter'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_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 0x00000000350ef1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cd8d760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cd8d7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_iter'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_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'>, '__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 0x0000000037feab88> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...'test_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 0x0000000037fb3920> 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 0x0000000037fb3920> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...'test_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'>, '__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'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x0000000037fbbb08> key = (((True, True, True, 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 0x0000000037fbbb08> 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 0x0000000037fbbb08> 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 0x0000000037fbbb08> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x00000000382e0360> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000383c41a8> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f91fd41fe60>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f91fd41fea0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f91fd41fec0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000030c31440>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x00000000380200c8>, <W_TypeObject 'GenericAlias' at 0x2ea6cd40>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x34e17600> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x34e17600> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x34e17600> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x34e17600> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x34802410>> w_obj = <W_TypeObject 'ellipsis' at 0x34e17600> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x34e17600>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x34802410>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x34e17600> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x34802410>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x34802410>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x34802410>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _______________ ERROR at setup of AppTestArrayModule.test_index ________________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000002f995718>, 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_index'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_index'>} 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 0x00007f91f8913670> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000350ef1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cd8d760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cd8d7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_index'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_index'>} 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 0x00000000350ef1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cd8d760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cd8d7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_index'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_index'>} 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_index'>, '__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 0x000000003236f830> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...test_index'>, '__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 0x0000000038196de0> 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 0x0000000038196de0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...test_index'>, '__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_index'>, '__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_index'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x0000000036e5be88> key = (((True, True, True, 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 0x0000000036e5be88> 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 0x0000000036e5be88> 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 0x0000000036e5be88> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x00000000384e4be0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000377ec0c8> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f91fd41fe60>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f91fd41fea0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f91fd41fec0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000030c31440>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000036e62448>, <W_TypeObject 'GenericAlias' at 0x36d3bc90>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x37dc5018> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x37dc5018> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x37dc5018> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x37dc5018> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x331b2820>> w_obj = <W_TypeObject 'ellipsis' at 0x37dc5018> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x37dc5018>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x331b2820>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x37dc5018> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x331b2820>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x331b2820>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x331b2820>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _____________ ERROR at setup of AppTestArrayModule.test_slice_get ______________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x00000000388f6020>, 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_slice_get'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_slice_get'>} 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 0x00007f91f8913670> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000350ef1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cd8d760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cd8d7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_slice_get'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_slice_get'>} 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 0x00000000350ef1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cd8d760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cd8d7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_slice_get'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_slice_get'>} 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_slice_get'>, '__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 0x000000003920bdd0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._slice_get'>, '__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 0x000000003921eda0> 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 0x000000003921eda0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._slice_get'>, '__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_slice_get'>, '__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_slice_get'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x00000000392231a0> key = (((True, True, True, 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 0x00000000392231a0> 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 0x00000000392231a0> 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 0x00000000392231a0> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000002d2210a0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000002f2f2560> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f91fd41fe60>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f91fd41fea0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f91fd41fec0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000030c31440>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000039223718>, <W_TypeObject 'GenericAlias' at 0x32619980>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x32c10ec8> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x32c10ec8> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x32c10ec8> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x32c10ec8> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x30928630>> w_obj = <W_TypeObject 'ellipsis' at 0x32c10ec8> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x32c10ec8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x30928630>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x32c10ec8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x30928630>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x30928630>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x30928630>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ____________ ERROR at setup of AppTestArrayModule.test_slice_object ____________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000035ffd100>, 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_slice_object'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_slice_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 0x00007f91f8913670> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000350ef1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cd8d760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cd8d7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_slice_object'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_slice_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 0x00000000350ef1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cd8d760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cd8d7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_slice_object'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_slice_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_slice_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 0x0000000030efac78> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ice_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 0x0000000037075ae0> 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 0x0000000037075ae0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ice_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_slice_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_slice_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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x000000003818c1e0> key = (((True, True, True, 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 0x000000003818c1e0> 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 0x000000003818c1e0> 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 0x000000003818c1e0> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000036d5d420> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000037626b48> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f91fd41fe60>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f91fd41fea0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f91fd41fec0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000030c31440>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000003818c758>, <W_TypeObject 'GenericAlias' at 0x370ed590>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x389849f8> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x389849f8> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x389849f8> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x389849f8> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x34a0e0e0>> w_obj = <W_TypeObject 'ellipsis' at 0x389849f8> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x389849f8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x34a0e0e0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x389849f8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x34a0e0e0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x34a0e0e0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x34a0e0e0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _______________ ERROR at setup of AppTestArrayModule.test_buffer _______________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x00000000328a1268>, 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_buffer'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_buffer'>} 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 0x00007f91f8913670> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000350ef1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cd8d760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cd8d7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_buffer'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_buffer'>} 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 0x00000000350ef1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cd8d760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cd8d7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_buffer'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_buffer'>} 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_buffer'>, '__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 0x00000000345fd600> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...est_buffer'>, '__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 0x000000003a083220> 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 0x000000003a083220> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...est_buffer'>, '__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_buffer'>, '__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_buffer'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x000000003a086598> key = (((True, True, True, 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 0x000000003a086598> 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 0x000000003a086598> 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 0x000000003a086598> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000003a268060> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000038921280> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f91fd41fe60>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f91fd41fea0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f91fd41fec0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000030c31440>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000003a086b10>, <W_TypeObject 'GenericAlias' at 0x31ce2790>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x323a1f68> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x323a1f68> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x323a1f68> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x323a1f68> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x34a12f80>> w_obj = <W_TypeObject 'ellipsis' at 0x323a1f68> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x323a1f68>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x34a12f80>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x323a1f68> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x34a12f80>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x34a12f80>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x34a12f80>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ___________ ERROR at setup of AppTestArrayModule.test_releasebuffer ____________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000003774b9e8>, 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_releasebuffer'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_releasebuffer'>} 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 0x00007f91f8913670> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000350ef1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cd8d760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cd8d7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_releasebuffer'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_releasebuffer'>} 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 0x00000000350ef1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cd8d760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cd8d7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_releasebuffer'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_releasebuffer'>} 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_releasebuffer'>, '__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 0x000000003829b100> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...easebuffer'>, '__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 0x0000000038366f20> 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 0x0000000038366f20> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...easebuffer'>, '__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_releasebuffer'>, '__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_releasebuffer'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x00000000370e1cc8> key = (((True, True, True, 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 0x00000000370e1cc8> 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 0x00000000370e1cc8> 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 0x00000000370e1cc8> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000038634960> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000034d32ec8> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f91fd41fe60>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f91fd41fea0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f91fd41fec0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000030c31440>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x00000000370ecfa8>, <W_TypeObject 'GenericAlias' at 0x370d2528>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x387eeb80> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x387eeb80> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x387eeb80> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x387eeb80> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x34520670>> w_obj = <W_TypeObject 'ellipsis' at 0x387eeb80> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x387eeb80>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x34520670>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x387eeb80> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x34520670>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x34520670>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x34520670>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _____________ ERROR at setup of AppTestArrayModule.test_Py_buffer ______________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000003054ff88>, 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_Py_buffer'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_Py_buffer'>} 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 0x00007f91f8913670> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000350ef1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cd8d760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cd8d7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_Py_buffer'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_Py_buffer'>} 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 0x00000000350ef1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cd8d760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cd8d7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_Py_buffer'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_Py_buffer'>} 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_Py_buffer'>, '__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 0x00000000398ce4f8> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._Py_buffer'>, '__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 0x00000000399065e0> 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 0x00000000399065e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._Py_buffer'>, '__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_Py_buffer'>, '__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_Py_buffer'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x00000000398fc6e8> key = (((True, True, True, 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 0x00000000398fc6e8> 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 0x00000000398fc6e8> 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 0x00000000398fc6e8> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000003a2eb2a0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000002d740368> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f91fd41fe60>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f91fd41fea0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f91fd41fec0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000030c31440>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x00000000398fcc60>, <W_TypeObject 'GenericAlias' at 0x3235fda8>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x323d5c20> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x323d5c20> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x323d5c20> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x323d5c20> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x33621ac0>> w_obj = <W_TypeObject 'ellipsis' at 0x323d5c20> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x323d5c20>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x33621ac0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x323d5c20> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x33621ac0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x33621ac0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x33621ac0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ______________ ERROR at setup of AppTestArrayModule.test_0d_view _______________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000003830c890>, 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_0d_view'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_0d_view'>} 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 0x00007f91f8913670> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000350ef1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cd8d760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cd8d7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_0d_view'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_0d_view'>} 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 0x00000000350ef1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cd8d760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cd8d7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_0d_view'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_0d_view'>} 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_0d_view'>, '__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 0x000000003598a930> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...st_0d_view'>, '__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 0x0000000036dd5660> 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 0x0000000036dd5660> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...st_0d_view'>, '__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_0d_view'>, '__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_0d_view'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x00000000360e6db0> key = (((True, True, True, 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 0x00000000360e6db0> 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 0x00000000360e6db0> 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 0x00000000360e6db0> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000037d98de0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000037a511a0> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f91fd41fe60>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f91fd41fea0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f91fd41fec0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000030c31440>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x00000000360e7328>, <W_TypeObject 'GenericAlias' at 0x38640c28>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x350a0598> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x350a0598> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x350a0598> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x350a0598> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x33547980>> w_obj = <W_TypeObject 'ellipsis' at 0x350a0598> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x350a0598>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x33547980>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x350a0598> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x33547980>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x33547980>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x33547980>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ___________ ERROR at setup of AppTestArrayModule.test_binop_mul_impl ___________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000038bfbbc8>, 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_binop_mul_impl'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_binop_mul_impl'>} 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 0x00007f91f8913670> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000350ef1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cd8d760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cd8d7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_binop_mul_impl'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_binop_mul_impl'>} 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 0x00000000350ef1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cd8d760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cd8d7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_binop_mul_impl'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_binop_mul_impl'>} 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_binop_mul_impl'>, '__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 0x0000000035b70cf0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...p_mul_impl'>, '__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 0x000000003a3121a0> 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 0x000000003a3121a0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...p_mul_impl'>, '__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_binop_mul_impl'>, '__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_binop_mul_impl'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x0000000039c32950> key = (((True, True, True, 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 0x0000000039c32950> 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 0x0000000039c32950> 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 0x0000000039c32950> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000003a3954e0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000035884790> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f91fd41fe60>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f91fd41fea0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f91fd41fec0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000030c31440>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000039c32ec8>, <W_TypeObject 'GenericAlias' at 0x3277de18>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x310d2de8> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x310d2de8> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x310d2de8> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x310d2de8> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2f1b7540>> w_obj = <W_TypeObject 'ellipsis' at 0x310d2de8> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x310d2de8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2f1b7540>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x310d2de8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2f1b7540>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2f1b7540>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2f1b7540>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError __________ ERROR at setup of AppTestArrayModule.test_subclass_dealloc __________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000031780548>, 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_subclass_dealloc'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_subclass_dealloc'>} 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 0x00007f91f8913670> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000350ef1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cd8d760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cd8d7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_subclass_dealloc'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_subclass_dealloc'>} 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 0x00000000350ef1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cd8d760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cd8d7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_subclass_dealloc'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_subclass_dealloc'>} 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_subclass_dealloc'>, '__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 0x0000000034627e20> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ss_dealloc'>, '__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 0x0000000038367d60> 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 0x0000000038367d60> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ss_dealloc'>, '__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_subclass_dealloc'>, '__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_subclass_dealloc'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x000000003813bd38> key = (((True, True, True, 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 0x000000003813bd38> 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 0x000000003813bd38> 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 0x000000003813bd38> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x00000000383f8120> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000037102448> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f91fd41fe60>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f91fd41fea0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f91fd41fec0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000030c31440>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000003812c2f8>, <W_TypeObject 'GenericAlias' at 0x360be2c0>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x38232c98> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x38232c98> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x38232c98> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x38232c98> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x33c90ca0>> w_obj = <W_TypeObject 'ellipsis' at 0x38232c98> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x38232c98>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x33c90ca0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x38232c98> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x33c90ca0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x33c90ca0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x33c90ca0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _____________ ERROR at setup of AppTestArrayModule.test_string_buf _____________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x00000000348567a0>, 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_string_buf'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_string_buf'>} 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 0x00007f91f8913670> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000350ef1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cd8d760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cd8d7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_string_buf'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_string_buf'>} 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 0x00000000350ef1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cd8d760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cd8d7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_string_buf'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_string_buf'>} 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_string_buf'>, '__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 0x0000000034fb62a0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...string_buf'>, '__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 0x00000000372b3320> 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 0x00000000372b3320> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...string_buf'>, '__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_string_buf'>, '__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_string_buf'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x00000000372e8a68> key = (((True, True, True, 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 0x00000000372e8a68> 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 0x00000000372e8a68> 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 0x00000000372e8a68> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000039e6cc60> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000037372f00> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f91fd41fe60>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f91fd41fea0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f91fd41fec0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000030c31440>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x00000000372e8fe0>, <W_TypeObject 'GenericAlias' at 0x31be9830>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x31de4db0> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x31de4db0> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x31de4db0> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x31de4db0> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x34988b90>> w_obj = <W_TypeObject 'ellipsis' at 0x31de4db0> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x31de4db0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x34988b90>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x31de4db0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x34988b90>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x34988b90>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x34988b90>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ______________ ERROR at setup of AppTestArrayModule.test_subclass ______________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000003411b2e0>, 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_subclass'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_subclass'>} 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 0x00007f91f8913670> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000350ef1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cd8d760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cd8d7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_subclass'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_subclass'>} 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 0x00000000350ef1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cd8d760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cd8d7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_subclass'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_subclass'>} 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_subclass'>, '__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 0x0000000035ab3ec0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_subclass'>, '__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 0x00000000383b6720> 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 0x00000000383b6720> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_subclass'>, '__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_subclass'>, '__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_subclass'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x00000000395c60c8> key = (((True, True, True, 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 0x00000000395c60c8> 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 0x00000000395c60c8> 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 0x00000000395c60c8> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x00000000385803e0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000370d1360> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f91fd41fe60>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f91fd41fea0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f91fd41fec0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000030c31440>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x00000000395c6a30>, <W_TypeObject 'GenericAlias' at 0x39e859b8>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x39e7b750> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x39e7b750> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x39e7b750> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x39e7b750> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x34b5d7f0>> w_obj = <W_TypeObject 'ellipsis' at 0x39e7b750> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x39e7b750>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x34b5d7f0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x39e7b750> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x34b5d7f0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x34b5d7f0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x34b5d7f0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _________ ERROR at setup of AppTestArrayModule.test_unicode_readbuffer _________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x00000000345f6f20>, 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_unicode_readbuffer'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_unicode_readbuffer'>} 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 0x00007f91f8913670> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000350ef1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cd8d760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cd8d7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_unicode_readbuffer'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_unicode_readbuffer'>} 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 0x00000000350ef1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cd8d760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cd8d7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_unicode_readbuffer'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_unicode_readbuffer'>} 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_unicode_readbuffer'>, '__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 0x00000000348f64f8> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...readbuffer'>, '__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 0x00000000396c1760> 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 0x00000000396c1760> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...readbuffer'>, '__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_unicode_readbuffer'>, '__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_unicode_readbuffer'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x00000000396e4138> key = (((True, True, True, 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 0x00000000396e4138> 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 0x00000000396e4138> 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 0x00000000396e4138> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000039df81e0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000039e09830> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f91fd41fe60>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f91fd41fea0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f91fd41fec0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000030c31440>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x00000000396e46b0>, <W_TypeObject 'GenericAlias' at 0x38acc4b8>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x38aa8218> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x38aa8218> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x38aa8218> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x38aa8218> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x32633db0>> w_obj = <W_TypeObject 'ellipsis' at 0x38aa8218> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x38aa8218>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x32633db0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x38aa8218> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x32633db0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x32633db0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x32633db0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ______________ ERROR at setup of AppTestArrayModule.test_readinto ______________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000003738bb50>, 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_readinto'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_readinto'>} 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 0x00007f91f8913670> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000350ef1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cd8d760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cd8d7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_readinto'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_readinto'>} 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 0x00000000350ef1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cd8d760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cd8d7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_readinto'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_readinto'>} 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_readinto'>, '__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 0x000000003598a6d8> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_readinto'>, '__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 0x0000000036005360> 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 0x0000000036005360> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_readinto'>, '__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_readinto'>, '__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_readinto'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x000000003857d670> key = (((True, True, True, 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 0x000000003857d670> 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 0x000000003857d670> 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 0x000000003857d670> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000003602eea0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000036e3e218> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f91fd41fe60>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f91fd41fea0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f91fd41fec0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000030c31440>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000038586598>, <W_TypeObject 'GenericAlias' at 0x3813b520>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x38483478> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x38483478> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x38483478> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x38483478> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2d954df0>> w_obj = <W_TypeObject 'ellipsis' at 0x38483478> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x38483478>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2d954df0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x38483478> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2d954df0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2d954df0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2d954df0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ______________ ERROR at setup of AppTestArrayModule.test_iowrite _______________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000003238b790>, 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_iowrite'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_iowrite'>} 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 0x00007f91f8913670> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000350ef1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cd8d760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cd8d7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_iowrite'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_iowrite'>} 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 0x00000000350ef1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cd8d760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cd8d7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_iowrite'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_iowrite'>} 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_iowrite'>, '__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 0x000000003604d218> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...st_iowrite'>, '__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 0x000000003a02baa0> 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 0x000000003a02baa0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...st_iowrite'>, '__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_iowrite'>, '__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_iowrite'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x000000003a07e2f8> key = (((True, True, True, 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 0x000000003a07e2f8> 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 0x000000003a07e2f8> 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 0x000000003a07e2f8> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000039f369e0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000039f72448> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f91fd41fe60>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f91fd41fea0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f91fd41fec0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000030c31440>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000003a07e870>, <W_TypeObject 'GenericAlias' at 0x37c28330>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x37c7ffa0> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x37c7ffa0> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x37c7ffa0> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x37c7ffa0> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3347b460>> w_obj = <W_TypeObject 'ellipsis' at 0x37c7ffa0> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x37c7ffa0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3347b460>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x37c7ffa0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3347b460>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3347b460>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3347b460>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ___ ERROR at setup of AppTestArrayModule.test_getitem_via_PySequence_GetItem ___ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000036611628>, 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_getitem_via_PySequence_GetItem'...all__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_getitem_via_PySequence_GetItem'>} 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 0x00007f91f8913670> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000350ef1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cd8d760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cd8d7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_getitem_via_PySequence_GetItem'...all__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_getitem_via_PySequence_GetItem'>} 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 0x00000000350ef1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cd8d760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cd8d7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_getitem_via_PySequence_GetItem'...all__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_getitem_via_PySequence_GetItem'>} 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_getitem_via_PySequence_GetItem'>, '__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 0x0000000034e3e138> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ce_GetItem'>, '__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 0x0000000033dcf8e0> 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 0x0000000033dcf8e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ce_GetItem'>, '__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_getitem_via_PySequence_GetItem'>, '__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_getitem_via_PySequence_GetItem'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x0000000034584598> key = (((True, True, True, 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 0x0000000034584598> 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 0x0000000034584598> 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 0x0000000034584598> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x00000000340218a0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000033d5ad40> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f91fd41fe60>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f91fd41fea0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f91fd41fec0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000030c31440>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000034584bb8>, <W_TypeObject 'GenericAlias' at 0x36ea11a0>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x37753c20> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x37753c20> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x37753c20> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x37753c20> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2fdf4670>> w_obj = <W_TypeObject 'ellipsis' at 0x37753c20> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x37753c20>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2fdf4670>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x37753c20> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2fdf4670>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2fdf4670>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2fdf4670>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ______ ERROR at setup of AppTestArrayModule.test_subclass_with_attribute _______ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000034240890>, 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_subclass_with_attribute'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_subclass_with_attribute'>} 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 0x00007f91f8913670> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000350ef1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cd8d760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cd8d7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_subclass_with_attribute'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_subclass_with_attribute'>} 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 0x00000000350ef1a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002cd8d760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002cd8d7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_subclass_with_attribute'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_subclass_with_attribute'>} 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_subclass_with_attribute'>, '__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 0x00000000332d5d08> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._attribute'>, '__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 0x0000000038bcd520> 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 0x0000000038bcd520> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._attribute'>, '__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_subclass_with_attribute'>, '__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_subclass_with_attribute'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x00000000376c61e0> key = (((True, True, True, 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 0x00000000376c61e0> 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 0x00000000376c61e0> 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 0x00000000376c61e0> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000037ab6160> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000036b9d830> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f91fd41fe60>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f91fd41fea0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f91fd41fec0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000030c31440>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x00000000376c6758>, <W_TypeObject 'GenericAlias' at 0x35f0fa28>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x35f01e88> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x35f01e88> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x35f01e88> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x35f01e88> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x33da0490>> w_obj = <W_TypeObject 'ellipsis' at 0x35f01e88> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x35f01e88>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x33da0490>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x35f01e88> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x33da0490>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x33da0490>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x33da0490>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ========================== 18 error in 74.15 seconds =========================== ++ 02:43:56 starting module/cpyext/test/test_classobject.py [55 started in total] __ module/cpyext/test/test_cell.py [52 done in total, somefailed=True] ________ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 1 items module/cpyext/test/test_cell.py E ==================================== ERRORS ==================================== _________________ ERROR at setup of AppTestCell.test_cell_type _________________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x00000000157824d0>, 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_cell_type'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_cell_type'>} 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 0x00007f50a91136a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000154039e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000df17760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000df177a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_cell_type'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_cell_type'>} 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 0x00000000154039e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000000df17760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000000df177a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_cell_type'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_cell_type'>} 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_cell_type'>, '__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 0x0000000015de0f98> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._cell_type'>, '__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 0x00000000158f4ae0> 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 0x00000000158f4ae0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._cell_type'>, '__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_cell_type'>, '__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_cell_type'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x000000001578edb0> key = (((True, True, True, 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 0x000000001578edb0> 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 0x000000001578edb0> 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 0x000000001578edb0> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000013e8b620> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000016ad7910> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f50adbe6e60>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f50adbe6ea0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f50adbe6ec0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000000fb47d00>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x00000000157583a0>, <W_TypeObject 'GenericAlias' at 0x1753f398>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x17d134b0> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x17d134b0> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x17d134b0> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x17d134b0> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x15bb5990>> w_obj = <W_TypeObject 'ellipsis' at 0x17d134b0> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x17d134b0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x15bb5990>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x17d134b0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x15bb5990>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x15bb5990>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x15bb5990>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError =========================== 1 error in 6.13 seconds ============================ ++ 02:44:09 starting module/cpyext/test/test_codecs.py [56 started in total] __ module/cpyext/test/test_capsule.py [53 done in total, somefailed=True] _____ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 3 items module/cpyext/test/test_capsule.py EEE ==================================== ERRORS ==================================== _____________ ERROR at setup of AppTestCapsule.test_capsule_import _____________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x00000000361de980>, 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_capsule_import'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_capsule_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 0x00007f38382936a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000035cbdb20>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002d84f7a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002d84f7e0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_capsule_import'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_capsule_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 0x0000000035cbdb20>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002d84f7a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002d84f7e0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_capsule_import'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_capsule_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_capsule_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 0x00000000361e24d0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ule_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 0x00000000361a5a60> 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 0x00000000361a5a60> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ule_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_capsule_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_capsule_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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x00000000361d9e18> key = (((True, True, True, 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 0x00000000361d9e18> 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 0x00000000361d9e18> 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 0x00000000361d9e18> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x00000000366b6ea0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000036a56aa0> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f383c622e60>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f383c622ea0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f383c622ec0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000030ec9980>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x00000000362094e8>, <W_TypeObject 'GenericAlias' at 0x35110e20>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x343ee790> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x343ee790> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x343ee790> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x343ee790> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x35191240>> w_obj = <W_TypeObject 'ellipsis' at 0x343ee790> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x343ee790>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x35191240>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x343ee790> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x35191240>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x35191240>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x35191240>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ______________ ERROR at setup of AppTestCapsule.test_capsule_set _______________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000038944200>, 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_capsule_set'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_capsule_set'>} 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 0x00007f38382936a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000035cbdb20>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002d84f7a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002d84f7e0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_capsule_set'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_capsule_set'>} 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 0x0000000035cbdb20>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002d84f7a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002d84f7e0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_capsule_set'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_capsule_set'>} 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_capsule_set'>, '__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 0x00000000389925c0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...apsule_set'>, '__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 0x000000003897e3a0> 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 0x000000003897e3a0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...apsule_set'>, '__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_capsule_set'>, '__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_capsule_set'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x0000000038941600> key = (((True, True, True, 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 0x0000000038941600> 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 0x0000000038941600> 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 0x0000000038941600> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000038bbf560> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000038cb8a68> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f383c622e60>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f383c622ea0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f383c622ec0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000030ec9980>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000038941b78>, <W_TypeObject 'GenericAlias' at 0x31c9a720>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3258a288> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3258a288> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3258a288> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3258a288> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3534fed0>> w_obj = <W_TypeObject 'ellipsis' at 0x3258a288> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x3258a288>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3534fed0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x3258a288> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3534fed0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3534fed0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3534fed0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ___ ERROR at setup of AppTestCapsule.test_capsule_destructor_via_gc_collect ____ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x00000000316e5bc8>, 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_capsule_destructor_via_gc_colle...__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_capsule_destructor_via_gc_collect'>} 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 0x00007f38382936a8> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000035cbdb20>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002d84f7a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002d84f7e0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_capsule_destructor_via_gc_colle...__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_capsule_destructor_via_gc_collect'>} 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 0x0000000035cbdb20>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002d84f7a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002d84f7e0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_capsule_destructor_via_gc_colle...__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_capsule_destructor_via_gc_collect'>} 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_capsule_destructor_via_gc_collect'>, '__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 0x0000000033da3cb8> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...gc_collect'>, '__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 0x0000000036d684e0> 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 0x0000000036d684e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...gc_collect'>, '__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_capsule_destructor_via_gc_collect'>, '__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_capsule_destructor_via_gc_collect'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x0000000036cc3948> key = (((True, True, True, 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 0x0000000036cc3948> 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 0x0000000036cc3948> 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 0x0000000036cc3948> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000003853dda0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000385215c8> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f383c622e60>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f383c622ea0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f383c622ec0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x0000000030ec9980>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000036cc3ec0>, <W_TypeObject 'GenericAlias' at 0x38492170>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x37aae560> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x37aae560> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x37aae560> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x37aae560> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x33ec2f60>> w_obj = <W_TypeObject 'ellipsis' at 0x37aae560> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x37aae560>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x33ec2f60>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x37aae560> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x33ec2f60>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x33ec2f60>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x33ec2f60>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError =========================== 3 error in 14.93 seconds =========================== ++ 02:44:10 starting module/cpyext/test/test_complexobject.py [57 started in total] __ module/cpyext/test/test_classobject.py [54 done in total, somefailed=True] _ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 2 items module/cpyext/test/test_classobject.py EE ==================================== ERRORS ==================================== _________ ERROR at setup of AppTestInstanceMethod.test_instancemethod __________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000025661100>, 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_instancemethod'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_instancemethod'>} 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 0x00007f4553c91670> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002507d5a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000001ca5d760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001ca5d7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_instancemethod'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_instancemethod'>} 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 0x000000002507d5a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000001ca5d760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001ca5d7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_instancemethod'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_instancemethod'>} 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_instancemethod'>, '__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 0x000000002566a200> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ancemethod'>, '__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 0x0000000025643aa0> 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 0x0000000025643aa0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ancemethod'>, '__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_instancemethod'>, '__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_instancemethod'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x000000002564df30> key = (((True, True, True, 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 0x000000002564df30> 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 0x000000002564df30> 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 0x000000002564df30> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000025d2f760> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000002621d280> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f4553c70e60>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f4553c70ea0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f4553c70ec0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000001e598aa0>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x00000000256744f0>, <W_TypeObject 'GenericAlias' at 0x2420b1d8>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x24b155c8> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x24b155c8> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x24b155c8> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x24b155c8> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d60ace0>> w_obj = <W_TypeObject 'ellipsis' at 0x24b155c8> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x24b155c8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d60ace0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x24b155c8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d60ace0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d60ace0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1d60ace0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ERROR at setup of AppTestInstanceMethod.test_instancemethod_cpyext_attributes _ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000027918ae8>, 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_instancemethod_cpyext_attribute...l__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_instancemethod_cpyext_attributes'>} 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 0x00007f4553c91670> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002507d5a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000001ca5d760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001ca5d7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_instancemethod_cpyext_attribute...l__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_instancemethod_cpyext_attributes'>} 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 0x000000002507d5a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000001ca5d760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001ca5d7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_instancemethod_cpyext_attribute...l__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_instancemethod_cpyext_attributes'>} 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_instancemethod_cpyext_attributes'>, '__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 0x0000000025bcd0b0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...attributes'>, '__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 0x000000002797ae60> 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 0x000000002797ae60> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...attributes'>, '__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_instancemethod_cpyext_attributes'>, '__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_instancemethod_cpyext_attributes'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x00000000279c2410> key = (((True, True, True, 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 0x00000000279c2410> 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 0x00000000279c2410> 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 0x00000000279c2410> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000027bf0620> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000027d022f8> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f4553c70e60>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f4553c70ea0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f4553c70ec0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000001e598aa0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x00000000279c2988>, <W_TypeObject 'GenericAlias' at 0x220b0b48>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x209b6838> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x209b6838> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x209b6838> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x209b6838> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20ffef00>> w_obj = <W_TypeObject 'ellipsis' at 0x209b6838> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x209b6838>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20ffef00>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x209b6838> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20ffef00>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20ffef00>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x20ffef00>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError =========================== 2 error in 10.60 seconds =========================== ++ 02:44:16 starting module/cpyext/test/test_contextvars.py [58 started in total] __ module/cpyext/test/test_contextvars.py [55 done in total, somefailed=True] _ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 1 items module/cpyext/test/test_contextvars.py E ==================================== ERRORS ==================================== ________________ ERROR at setup of AppTestContext.test_context _________________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000001da7c4d0>, 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_context'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_context'>} 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 0x00007f6144a91638> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001eb57fa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000017a57760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000017a577a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_context'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_context'>} 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 0x000000001eb57fa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000017a57760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000017a577a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_context'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_context'>} 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_context'>, '__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 0x000000001f8028e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...st_context'>, '__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 0x000000001f07a960> 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 0x000000001f07a960> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...st_context'>, '__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_context'>, '__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_context'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x000000001dabed40> key = (((True, True, True, 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 0x000000001dabed40> 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 0x000000001dabed40> 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 0x000000001dabed40> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000001e6a0820> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000020c842f8> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6145272e80>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f6145272ec0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f6145272ee0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000001bab9de0>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000001dabf2b8>, <W_TypeObject 'GenericAlias' at 0x215cf8a0>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21d84058> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21d84058> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21d84058> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x21d84058> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e3ea360>> w_obj = <W_TypeObject 'ellipsis' at 0x21d84058> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x21d84058>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e3ea360>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x21d84058> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e3ea360>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e3ea360>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1e3ea360>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError =========================== 1 error in 6.17 seconds ============================ ++ 02:44:34 starting module/cpyext/test/test_cpyext.py [59 started in total] __ module/cpyext/test/test_codecs.py [56 done in total, somefailed=True] ______ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 3 items module/cpyext/test/test_codecs.py EEE ==================================== ERRORS ==================================== ________________ ERROR at setup of TestCodecs.test_incremental _________________ item = <Function 'test_incremental'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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:481: in __init__ self.initialize() objspace/std/objspace.py:118: in initialize self.setup_builtin_modules() interpreter/baseobjspace.py:739: in setup_builtin_modules self.fromcache(State).build_api() module/cpyext/state.py:128: in build_api self.api_lib = str(api.build_bridge(self.space)) module/cpyext/api.py:1468: in build_bridge builder.attach_all(space) module/cpyext/api.py:1535: in attach_all attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1497: in attach_recursively make_ref(space, w_type)) module/cpyext/pyobject.py:510: in make_ref return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:483: in get_pyobj_and_incref pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: in as_pyobj py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:326: in create_ref track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:375: in track_reference w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:132: in _cpyext_attach_pyobj rawrefcount.create_link_pypy(self, py_obj) ../rpython/rlib/rawrefcount.py:187: in create_link_pypy assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:102: in _ob_link_get return ob.c_ob_pypy_link _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2a543090>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ______________ ERROR at setup of TestCodecs.test_encoder_decoder _______________ item = <Function 'test_encoder_decoder'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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:481: in __init__ self.initialize() objspace/std/objspace.py:118: in initialize self.setup_builtin_modules() interpreter/baseobjspace.py:739: in setup_builtin_modules self.fromcache(State).build_api() module/cpyext/state.py:128: in build_api self.api_lib = str(api.build_bridge(self.space)) module/cpyext/api.py:1468: in build_bridge builder.attach_all(space) module/cpyext/api.py:1535: in attach_all attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1497: in attach_recursively make_ref(space, w_type)) module/cpyext/pyobject.py:510: in make_ref return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:483: in get_pyobj_and_incref pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: in as_pyobj py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:326: in create_ref track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:375: in track_reference w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:132: in _cpyext_attach_pyobj rawrefcount.create_link_pypy(self, py_obj) ../rpython/rlib/rawrefcount.py:187: in create_link_pypy assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:102: in _ob_link_get return ob.c_ob_pypy_link _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2cf6a170>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError __________ ERROR at setup of AppTestUnicodeObject.test_encode_decode ___________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000030c8c098>, 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_encode_decode'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_encode_decode'>} 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 0x00007fe134d13670> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002c9729e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000255977e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000025597820>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_encode_decode'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_encode_decode'>} 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 0x000000002c9729e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000255977e0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000025597820>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_encode_decode'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_encode_decode'>} 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_encode_decode'>, '__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 0x00000000314b67c8> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ode_decode'>, '__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 0x00000000314c8120> 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 0x00000000314c8120> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ode_decode'>, '__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_encode_decode'>, '__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_encode_decode'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x00000000314cc288> key = (((True, True, True, 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 0x00000000314cc288> 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 0x00000000314cc288> 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 0x00000000314cc288> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000029519d20> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000002a1709f8> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fe139822e80>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7fe139822ec0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7fe139822ee0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000000292cc918>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x00000000314cc800>, <W_TypeObject 'GenericAlias' at 0x2bd83b40>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2c1410f8> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2c1410f8> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2c1410f8> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2c1410f8> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2abb3540>> w_obj = <W_TypeObject 'ellipsis' at 0x2c1410f8> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x2c1410f8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2abb3540>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x2c1410f8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2abb3540>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2abb3540>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2abb3540>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError =========================== 3 error in 14.89 seconds =========================== ++ 02:44:37 starting module/cpyext/test/test_datetime.py [60 started in total] __ module/cpyext/test/test_complexobject.py [57 done in total, somefailed=True] ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 6 items module/cpyext/test/test_complexobject.py EEEEEE ==================================== ERRORS ==================================== ____________ ERROR at setup of TestComplexObject.test_complexobject ____________ item = <Function 'test_complexobject'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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:481: in __init__ self.initialize() objspace/std/objspace.py:118: in initialize self.setup_builtin_modules() interpreter/baseobjspace.py:739: in setup_builtin_modules self.fromcache(State).build_api() module/cpyext/state.py:128: in build_api self.api_lib = str(api.build_bridge(self.space)) module/cpyext/api.py:1468: in build_bridge builder.attach_all(space) module/cpyext/api.py:1535: in attach_all attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1497: in attach_recursively make_ref(space, w_type)) module/cpyext/pyobject.py:510: in make_ref return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:483: in get_pyobj_and_incref pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: in as_pyobj py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:326: in create_ref track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:375: in track_reference w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:132: in _cpyext_attach_pyobj rawrefcount.create_link_pypy(self, py_obj) ../rpython/rlib/rawrefcount.py:187: in create_link_pypy assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:102: in _ob_link_get return ob.c_ob_pypy_link _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x24699400>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ______________ ERROR at setup of AppTestCComplex.test_AsCComplex _______________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000029574bd8>, 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_AsCComplex'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_AsCComplex'>} 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 0x00007f7acaa916e0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000026e12fa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000001e8357a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001e8357e0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_AsCComplex'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_AsCComplex'>} 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 0x0000000026e12fa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000001e8357a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001e8357e0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_AsCComplex'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_AsCComplex'>} 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_AsCComplex'>, '__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 0x0000000027ac4200> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...AsCComplex'>, '__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 0x00000000295e4660> 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 0x00000000295e4660> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...AsCComplex'>, '__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_AsCComplex'>, '__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_AsCComplex'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x00000000295e2c98> key = (((True, True, True, 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 0x00000000295e2c98> 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 0x00000000295e2c98> 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 0x00000000295e2c98> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000029868860> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000299933d0> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f7acf4a9e80>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f7acf4a9ec0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f7acf4a9ee0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000001f92db78>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x00000000295e3210>, <W_TypeObject 'GenericAlias' at 0x29e67bb0>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x29f4cd08> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x29f4cd08> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x29f4cd08> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x29f4cd08> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x24d5b7d0>> w_obj = <W_TypeObject 'ellipsis' at 0x29f4cd08> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x29f4cd08>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x24d5b7d0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x29f4cd08> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x24d5b7d0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x24d5b7d0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x24d5b7d0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _____________ ERROR at setup of AppTestCComplex.test_FromCComplex ______________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000001eec3718>, 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_FromCComplex'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_FromCComplex'>} 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 0x00007f7acaa916e0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000026e12fa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000001e8357a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001e8357e0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_FromCComplex'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_FromCComplex'>} 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 0x0000000026e12fa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000001e8357a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001e8357e0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_FromCComplex'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_FromCComplex'>} 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_FromCComplex'>, '__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 0x0000000023704520> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...omCComplex'>, '__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 0x00000000296c6920> 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 0x00000000296c6920> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...omCComplex'>, '__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_FromCComplex'>, '__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_FromCComplex'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x0000000029d4a560> key = (((True, True, True, 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 0x0000000029d4a560> 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 0x0000000029d4a560> 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 0x0000000029d4a560> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000029916620> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000026931ec0> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f7acf4a9e80>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f7acf4a9ec0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f7acf4a9ee0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000001f92db78>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000029d4aad8>, <W_TypeObject 'GenericAlias' at 0x28b54c28>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2933e8a8> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2933e8a8> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2933e8a8> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2933e8a8> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x248ae9d0>> w_obj = <W_TypeObject 'ellipsis' at 0x2933e8a8> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x2933e8a8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x248ae9d0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x2933e8a8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x248ae9d0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x248ae9d0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x248ae9d0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _________ ERROR at setup of AppTestCComplex.test_PyComplex_to_WComplex _________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000027a76020>, 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_PyComplex_to_WComplex'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_PyComplex_to_WComplex'>} 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 0x00007f7acaa916e0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000026e12fa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000001e8357a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001e8357e0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_PyComplex_to_WComplex'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_PyComplex_to_WComplex'>} 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 0x0000000026e12fa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000001e8357a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001e8357e0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_PyComplex_to_WComplex'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_PyComplex_to_WComplex'>} 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_PyComplex_to_WComplex'>, '__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 0x00000000271a1290> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...o_WComplex'>, '__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 0x000000002ad965a0> 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 0x000000002ad965a0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...o_WComplex'>, '__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_PyComplex_to_WComplex'>, '__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_PyComplex_to_WComplex'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x000000002ad2df30> key = (((True, True, True, 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 0x000000002ad2df30> 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 0x000000002ad2df30> 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 0x000000002ad2df30> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000002ae8eba0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000002aef5fa0> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f7acf4a9e80>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f7acf4a9ec0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f7acf4a9ee0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000001f92db78>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000002ad9c4f0>, <W_TypeObject 'GenericAlias' at 0x2375b130>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x22c92bb8> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x22c92bb8> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x22c92bb8> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x22c92bb8> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x25a040e0>> w_obj = <W_TypeObject 'ellipsis' at 0x22c92bb8> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x22c92bb8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x25a040e0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x22c92bb8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x25a040e0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x25a040e0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x25a040e0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _________ ERROR at setup of AppTestCComplex.test_WComplex_to_PyComplex _________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x00000000298c4e30>, 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_WComplex_to_PyComplex'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_WComplex_to_PyComplex'>} 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 0x00007f7acaa916e0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000026e12fa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000001e8357a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001e8357e0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_WComplex_to_PyComplex'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_WComplex_to_PyComplex'>} 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 0x0000000026e12fa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000001e8357a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001e8357e0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_WComplex_to_PyComplex'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_WComplex_to_PyComplex'>} 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_WComplex_to_PyComplex'>, '__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 0x000000002050c160> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._PyComplex'>, '__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 0x0000000029b17360> 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 0x0000000029b17360> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._PyComplex'>, '__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_WComplex_to_PyComplex'>, '__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_WComplex_to_PyComplex'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x0000000028971050> key = (((True, True, True, 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 0x0000000028971050> 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 0x0000000028971050> 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 0x0000000028971050> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000029b89d60> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000027535de0> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f7acf4a9e80>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f7acf4a9ec0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f7acf4a9ee0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000001f92db78>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x00000000289715c8>, <W_TypeObject 'GenericAlias' at 0x29b08e90>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x29609018> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x29609018> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x29609018> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x29609018> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1f41d8f0>> w_obj = <W_TypeObject 'ellipsis' at 0x29609018> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x29609018>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1f41d8f0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x29609018> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1f41d8f0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1f41d8f0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x1f41d8f0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _________ ERROR at setup of AppTestCComplex.test_PyComplex_AsCComplex __________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000025722110>, 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_PyComplex_AsCComplex'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_PyComplex_AsCComplex'>} 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 0x00007f7acaa916e0> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000026e12fa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000001e8357a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001e8357e0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_PyComplex_AsCComplex'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_PyComplex_AsCComplex'>} 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 0x0000000026e12fa0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000001e8357a0>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000001e8357e0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_PyComplex_AsCComplex'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_PyComplex_AsCComplex'>} 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_PyComplex_AsCComplex'>, '__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 0x0000000024bef6f0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...AsCComplex'>, '__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 0x000000002aa364a0> 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 0x000000002aa364a0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...AsCComplex'>, '__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_PyComplex_AsCComplex'>, '__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_PyComplex_AsCComplex'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x000000002a9c5718> key = (((True, True, True, 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 0x000000002a9c5718> 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 0x000000002a9c5718> 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 0x000000002a9c5718> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000001fd96e20> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000002952bad0> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f7acf4a9e80>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f7acf4a9ec0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f7acf4a9ee0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000001f92db78>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000002a9c5c90>, <W_TypeObject 'GenericAlias' at 0x2425ead8>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x242e7ad0> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x242e7ad0> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x242e7ad0> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x242e7ad0> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x24df6e50>> w_obj = <W_TypeObject 'ellipsis' at 0x242e7ad0> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x242e7ad0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x24df6e50>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x242e7ad0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x24df6e50>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x24df6e50>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x24df6e50>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError =========================== 6 error in 27.14 seconds =========================== ++ 02:44:48 starting module/cpyext/test/test_dictobject.py [61 started in total] __ module/cpyext/test/test_bytesobject.py [58 done in total, somefailed=True] _ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 20 items module/cpyext/test/test_bytesobject.py EEEEEEEEEEEEEEEEEEEE ==================================== ERRORS ==================================== ____________ ERROR at setup of AppTestBytesObject.test_bytesobject _____________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000002b401790>, 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_bytesobject'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_bytesobject'>} 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 0x00007f369fb15600> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000294654a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000022e8f760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000022e8f7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_bytesobject'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_bytesobject'>} 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 0x00000000294654a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000022e8f760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000022e8f7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_bytesobject'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_bytesobject'>} 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_bytesobject'>, '__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 0x000000002b450b38> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ytesobject'>, '__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 0x000000002b44f1e0> 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 0x000000002b44f1e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ytesobject'>, '__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_bytesobject'>, '__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_bytesobject'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x000000002b454410> key = (((True, True, True, 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 0x000000002b454410> 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 0x000000002b454410> 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 0x000000002b454410> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000002b9aa8e0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000002bd51c58> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f36a4622e80>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f36a4622ec0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f36a4622ee0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000000246d77f8>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000002b454988>, <W_TypeObject 'GenericAlias' at 0x28346b48>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x29986c98> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x29986c98> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x29986c98> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x29986c98> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x29a9c330>> w_obj = <W_TypeObject 'ellipsis' at 0x29986c98> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x29986c98>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x29a9c330>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x29986c98> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x29a9c330>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x29a9c330>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x29a9c330>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _________ ERROR at setup of AppTestBytesObject.test_bytes_buffer_init __________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000002d365da8>, 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_buffer_init'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_bytes_buffer_init'>} 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 0x00007f369fb15600> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000294654a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000022e8f760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000022e8f7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_bytes_buffer_init'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_bytes_buffer_init'>} 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 0x00000000294654a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000022e8f760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000022e8f7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_bytes_buffer_init'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_bytes_buffer_init'>} 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_buffer_init'>, '__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 0x000000002b4bbe48> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...uffer_init'>, '__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 0x000000002d3cee20> 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 0x000000002d3cee20> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...uffer_init'>, '__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_buffer_init'>, '__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_buffer_init'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x000000002d3dd280> key = (((True, True, True, 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 0x000000002d3dd280> 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 0x000000002d3dd280> 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 0x000000002d3dd280> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000002d5e1320> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000002d6c7558> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f36a4622e80>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f36a4622ec0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f36a4622ee0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000000246d77f8>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000002d3dd7f8>, <W_TypeObject 'GenericAlias' at 0x2dab7050>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2db49360> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2db49360> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2db49360> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2db49360> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x29348380>> w_obj = <W_TypeObject 'ellipsis' at 0x2db49360> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x2db49360>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x29348380>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x2db49360> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x29348380>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x29348380>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x29348380>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ___________ ERROR at setup of AppTestBytesObject.test_bytes_tp_alloc ___________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000027ced538>, 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_tp_alloc'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_bytes_tp_alloc'>} 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 0x00007f369fb15600> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000294654a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000022e8f760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000022e8f7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_bytes_tp_alloc'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_bytes_tp_alloc'>} 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 0x00000000294654a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000022e8f760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000022e8f7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_bytes_tp_alloc'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_bytes_tp_alloc'>} 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_tp_alloc'>, '__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 0x00000000280753f8> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...s_tp_alloc'>, '__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 0x000000002c23f3e0> 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 0x000000002c23f3e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...s_tp_alloc'>, '__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_tp_alloc'>, '__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_tp_alloc'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x000000002d0e2a30> key = (((True, True, True, 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 0x000000002d0e2a30> 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 0x000000002d0e2a30> 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 0x000000002d0e2a30> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000002d350b20> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000002d8e54b0> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f36a4622e80>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f36a4622ec0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f36a4622ee0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000000246d77f8>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000002d0e2fa8>, <W_TypeObject 'GenericAlias' at 0x2c40c528>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2caa8170> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2caa8170> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2caa8170> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2caa8170> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2acb4900>> w_obj = <W_TypeObject 'ellipsis' at 0x2caa8170> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x2caa8170>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2acb4900>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x2caa8170> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2acb4900>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2acb4900>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2acb4900>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ______________ ERROR at setup of AppTestBytesObject.test_AsString ______________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000002b9f34c0>, 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_AsString'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_AsString'>} 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 0x00007f369fb15600> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000294654a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000022e8f760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000022e8f7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_AsString'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_AsString'>} 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 0x00000000294654a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000022e8f760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000022e8f7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_AsString'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_AsString'>} 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_AsString'>, '__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 0x000000002b89ad90> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_AsString'>, '__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 0x000000002f19fe20> 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 0x000000002f19fe20> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_AsString'>, '__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_AsString'>, '__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_AsString'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x000000002f1cf948> key = (((True, True, True, 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 0x000000002f1cf948> 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 0x000000002f1cf948> 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 0x000000002f1cf948> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000002f4442a0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000002f4a6d08> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f36a4622e80>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f36a4622ec0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f36a4622ee0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000000246d77f8>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000002f21f2b8>, <W_TypeObject 'GenericAlias' at 0x2f807cc8>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2f9e55c8> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2f9e55c8> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2f9e55c8> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2f9e55c8> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2964fa60>> w_obj = <W_TypeObject 'ellipsis' at 0x2f9e55c8> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x2f9e55c8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2964fa60>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x2f9e55c8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2964fa60>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2964fa60>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2964fa60>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ___________ ERROR at setup of AppTestBytesObject.test_manipulations ____________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000002a4d4db8>, 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_manipulations'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_manipulations'>} 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 0x00007f369fb15600> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000294654a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000022e8f760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000022e8f7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_manipulations'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_manipulations'>} 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 0x00000000294654a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000022e8f760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000022e8f7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_manipulations'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_manipulations'>} 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_manipulations'>, '__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 0x0000000027a12b10> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ipulations'>, '__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 0x000000002c008160> 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 0x000000002c008160> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ipulations'>, '__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_manipulations'>, '__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_manipulations'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x000000002c687d38> key = (((True, True, True, 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 0x000000002c687d38> 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 0x000000002c687d38> 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 0x000000002c687d38> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000002c23fd60> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000002d53c528> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f36a4622e80>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f36a4622ec0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f36a4622ee0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000000246d77f8>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000002c6da2f8>, <W_TypeObject 'GenericAlias' at 0x2de771d8>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2d1294e8> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2d1294e8> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2d1294e8> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2d1294e8> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2810b8b0>> w_obj = <W_TypeObject 'ellipsis' at 0x2d1294e8> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x2d1294e8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2810b8b0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x2d1294e8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2810b8b0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2810b8b0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2810b8b0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ______ ERROR at setup of AppTestBytesObject.test_py_bytes_as_string_None _______ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000002b6c5538>, 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_py_bytes_as_string_None'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_py_bytes_as_string_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 0x00007f369fb15600> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000294654a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000022e8f760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000022e8f7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_py_bytes_as_string_None'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_py_bytes_as_string_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 0x00000000294654a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000022e8f760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000022e8f7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_py_bytes_as_string_None'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_py_bytes_as_string_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_py_bytes_as_string_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 0x0000000028760610> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...tring_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 0x000000002c876820> 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 0x000000002c876820> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...tring_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_py_bytes_as_string_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_py_bytes_as_string_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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x000000002c878790> key = (((True, True, True, 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 0x000000002c878790> 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 0x000000002c878790> 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 0x000000002c878790> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000002ea6dde0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000002be6f0f8> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f36a4622e80>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f36a4622ec0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f36a4622ee0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000000246d77f8>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000002c878d08>, <W_TypeObject 'GenericAlias' at 0x2ecda678>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2dfb8e20> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2dfb8e20> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2dfb8e20> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2dfb8e20> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2a6cdd30>> w_obj = <W_TypeObject 'ellipsis' at 0x2dfb8e20> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x2dfb8e20>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2a6cdd30>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x2dfb8e20> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2a6cdd30>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2a6cdd30>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2a6cdd30>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError __________ ERROR at setup of AppTestBytesObject.test_AsStringAndSize ___________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000002df98368>, 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_AsStringAndSize'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_AsStringAndSize'>} 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 0x00007f369fb15600> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000294654a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000022e8f760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000022e8f7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_AsStringAndSize'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_AsStringAndSize'>} 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 0x00000000294654a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000022e8f760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000022e8f7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_AsStringAndSize'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_AsStringAndSize'>} 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_AsStringAndSize'>, '__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 0x000000002b9e6fc0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ingAndSize'>, '__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 0x000000002c2300a0> 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 0x000000002c2300a0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ingAndSize'>, '__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_AsStringAndSize'>, '__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_AsStringAndSize'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x000000002d81e598> key = (((True, True, True, 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 0x000000002d81e598> 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 0x000000002d81e598> 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 0x000000002d81e598> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000002c2fe7e0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000002dacdd00> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f36a4622e80>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f36a4622ec0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f36a4622ee0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000000246d77f8>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000002d81eb10>, <W_TypeObject 'GenericAlias' at 0x2f869b78>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2ea4b018> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2ea4b018> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2ea4b018> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2ea4b018> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x270d31c0>> w_obj = <W_TypeObject 'ellipsis' at 0x2ea4b018> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x2ea4b018>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x270d31c0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x2ea4b018> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x270d31c0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x270d31c0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x270d31c0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _____________ ERROR at setup of AppTestBytesObject.test_FromFormat _____________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000002ba22b60>, 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_FromFormat'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_FromFormat'>} 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 0x00007f369fb15600> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000294654a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000022e8f760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000022e8f7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_FromFormat'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_FromFormat'>} 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 0x00000000294654a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000022e8f760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000022e8f7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_FromFormat'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_FromFormat'>} 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_FromFormat'>, '__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 0x00000000296a7da8> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...FromFormat'>, '__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 0x000000002cdf9aa0> 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 0x000000002cdf9aa0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...FromFormat'>, '__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_FromFormat'>, '__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_FromFormat'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x000000002ce5c480> key = (((True, True, True, 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 0x000000002ce5c480> 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 0x000000002ce5c480> 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 0x000000002ce5c480> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000002ef618e0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000002e67b7f8> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f36a4622e80>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f36a4622ec0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f36a4622ee0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000000246d77f8>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000002ce5c9f8>, <W_TypeObject 'GenericAlias' at 0x28225e50>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2685f8d8> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2685f8d8> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2685f8d8> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2685f8d8> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x27ad3810>> w_obj = <W_TypeObject 'ellipsis' at 0x2685f8d8> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x2685f8d8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x27ad3810>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x2685f8d8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x27ad3810>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x27ad3810>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x27ad3810>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _____________ ERROR at setup of AppTestBytesObject.test_suboffsets _____________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000002d8e7b50>, 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_suboffsets'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_suboffsets'>} 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 0x00007f369fb15600> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000294654a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000022e8f760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000022e8f7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_suboffsets'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_suboffsets'>} 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 0x00000000294654a0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x0000000022e8f760>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000022e8f7a0>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_suboffsets'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_suboffsets'>} 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_suboffsets'>, '__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 0x0000000029e98e30> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...suboffsets'>, '__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 0x000000002d97c8e0> 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 0x000000002d97c8e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...suboffsets'>, '__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_suboffsets'>, '__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_suboffsets'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x000000002f240918> key = (((True, True, True, 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 0x000000002f240918> 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 0x000000002f240918> 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 0x000000002f240918> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000002defc820> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000002ea3c790> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f36a4622e80>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f36a4622ec0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f36a4622ee0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x00000000246d77f8>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000002f240e90>, <W_TypeObject 'GenericAlias' at 0x2aadb440>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2d901a28> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2d901a28> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2d901a28> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x2d901a28> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x29641f80>> w_obj = <W_TypeObject 'ellipsis' at 0x2d901a28> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x2d901a28>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x29641f80>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x2d901a28> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x29641f80>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x29641f80>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x29641f80>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _________________ ERROR at setup of TestBytes.test_FromObject __________________ item = <Function 'test_FromObject'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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:481: in __init__ self.initialize() objspace/std/objspace.py:118: in initialize self.setup_builtin_modules() interpreter/baseobjspace.py:739: in setup_builtin_modules self.fromcache(State).build_api() module/cpyext/state.py:128: in build_api self.api_lib = str(api.build_bridge(self.space)) module/cpyext/api.py:1468: in build_bridge builder.attach_all(space) module/cpyext/api.py:1535: in attach_all attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1497: in attach_recursively make_ref(space, w_type)) module/cpyext/pyobject.py:510: in make_ref return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:483: in get_pyobj_and_incref pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: in as_pyobj py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:326: in create_ref track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:375: in track_reference w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:132: in _cpyext_attach_pyobj rawrefcount.create_link_pypy(self, py_obj) ../rpython/rlib/rawrefcount.py:187: in create_link_pypy assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:102: in _ob_link_get return ob.c_ob_pypy_link _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x29281ad0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ________________ ERROR at setup of TestBytes.test_bytes_resize _________________ item = <Function 'test_bytes_resize'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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:481: in __init__ self.initialize() objspace/std/objspace.py:118: in initialize self.setup_builtin_modules() interpreter/baseobjspace.py:739: in setup_builtin_modules self.fromcache(State).build_api() module/cpyext/state.py:128: in build_api self.api_lib = str(api.build_bridge(self.space)) module/cpyext/api.py:1468: in build_bridge builder.attach_all(space) module/cpyext/api.py:1535: in attach_all attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1497: in attach_recursively make_ref(space, w_type)) module/cpyext/pyobject.py:510: in make_ref return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:483: in get_pyobj_and_incref pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: in as_pyobj py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:326: in create_ref track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:375: in track_reference w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:132: in _cpyext_attach_pyobj rawrefcount.create_link_pypy(self, py_obj) ../rpython/rlib/rawrefcount.py:187: in create_link_pypy assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:102: in _ob_link_get return ob.c_ob_pypy_link _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2a0dd310>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ________________ ERROR at setup of TestBytes.test_string_buffer ________________ item = <Function 'test_string_buffer'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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:481: in __init__ self.initialize() objspace/std/objspace.py:118: in initialize self.setup_builtin_modules() interpreter/baseobjspace.py:739: in setup_builtin_modules self.fromcache(State).build_api() module/cpyext/state.py:128: in build_api self.api_lib = str(api.build_bridge(self.space)) module/cpyext/api.py:1468: in build_bridge builder.attach_all(space) module/cpyext/api.py:1535: in attach_all attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1497: in attach_recursively make_ref(space, w_type)) module/cpyext/pyobject.py:510: in make_ref return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:483: in get_pyobj_and_incref pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: in as_pyobj py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:326: in create_ref track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:375: in track_reference w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:132: in _cpyext_attach_pyobj rawrefcount.create_link_pypy(self, py_obj) ../rpython/rlib/rawrefcount.py:187: in create_link_pypy assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:102: in _ob_link_get return ob.c_ob_pypy_link _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x29ca7590>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ___________________ ERROR at setup of TestBytes.test_Concat ____________________ item = <Function 'test_Concat'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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:481: in __init__ self.initialize() objspace/std/objspace.py:118: in initialize self.setup_builtin_modules() interpreter/baseobjspace.py:739: in setup_builtin_modules self.fromcache(State).build_api() module/cpyext/state.py:128: in build_api self.api_lib = str(api.build_bridge(self.space)) module/cpyext/api.py:1468: in build_bridge builder.attach_all(space) module/cpyext/api.py:1535: in attach_all attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1497: in attach_recursively make_ref(space, w_type)) module/cpyext/pyobject.py:510: in make_ref return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:483: in get_pyobj_and_incref pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: in as_pyobj py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:326: in create_ref track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:375: in track_reference w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:132: in _cpyext_attach_pyobj rawrefcount.create_link_pypy(self, py_obj) ../rpython/rlib/rawrefcount.py:187: in create_link_pypy assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:102: in _ob_link_get return ob.c_ob_pypy_link _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2a69f4c0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ________________ ERROR at setup of TestBytes.test_ConcatAndDel2 ________________ item = <Function 'test_ConcatAndDel2'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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:481: in __init__ self.initialize() objspace/std/objspace.py:118: in initialize self.setup_builtin_modules() interpreter/baseobjspace.py:739: in setup_builtin_modules self.fromcache(State).build_api() module/cpyext/state.py:128: in build_api self.api_lib = str(api.build_bridge(self.space)) module/cpyext/api.py:1468: in build_bridge builder.attach_all(space) module/cpyext/api.py:1535: in attach_all attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1497: in attach_recursively make_ref(space, w_type)) module/cpyext/pyobject.py:510: in make_ref return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:483: in get_pyobj_and_incref pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: in as_pyobj py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:326: in create_ref track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:375: in track_reference w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:132: in _cpyext_attach_pyobj rawrefcount.create_link_pypy(self, py_obj) ../rpython/rlib/rawrefcount.py:187: in create_link_pypy assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:102: in _ob_link_get return ob.c_ob_pypy_link _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x27940b30>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ___________________ ERROR at setup of TestBytes.test_format ____________________ item = <Function '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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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:481: in __init__ self.initialize() objspace/std/objspace.py:118: in initialize self.setup_builtin_modules() interpreter/baseobjspace.py:739: in setup_builtin_modules self.fromcache(State).build_api() module/cpyext/state.py:128: in build_api self.api_lib = str(api.build_bridge(self.space)) module/cpyext/api.py:1468: in build_bridge builder.attach_all(space) module/cpyext/api.py:1535: in attach_all attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1497: in attach_recursively make_ref(space, w_type)) module/cpyext/pyobject.py:510: in make_ref return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:483: in get_pyobj_and_incref pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: in as_pyobj py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:326: in create_ref track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:375: in track_reference w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:132: in _cpyext_attach_pyobj rawrefcount.create_link_pypy(self, py_obj) ../rpython/rlib/rawrefcount.py:187: in create_link_pypy assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:102: in _ob_link_get return ob.c_ob_pypy_link _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x24461ca0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError __________________ ERROR at setup of TestBytes.test_asbuffer ___________________ item = <Function 'test_asbuffer'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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:481: in __init__ self.initialize() objspace/std/objspace.py:118: in initialize self.setup_builtin_modules() interpreter/baseobjspace.py:739: in setup_builtin_modules self.fromcache(State).build_api() module/cpyext/state.py:128: in build_api self.api_lib = str(api.build_bridge(self.space)) module/cpyext/api.py:1468: in build_bridge builder.attach_all(space) module/cpyext/api.py:1535: in attach_all attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1497: in attach_recursively make_ref(space, w_type)) module/cpyext/pyobject.py:510: in make_ref return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:483: in get_pyobj_and_incref pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: in as_pyobj py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:326: in create_ref track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:375: in track_reference w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:132: in _cpyext_attach_pyobj rawrefcount.create_link_pypy(self, py_obj) ../rpython/rlib/rawrefcount.py:187: in create_link_pypy assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:102: in _ob_link_get return ob.c_ob_pypy_link _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2a82d8a0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ___________________ ERROR at setup of TestBytes.test_intern ____________________ item = <Function 'test_intern'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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:481: in __init__ self.initialize() objspace/std/objspace.py:118: in initialize self.setup_builtin_modules() interpreter/baseobjspace.py:739: in setup_builtin_modules self.fromcache(State).build_api() module/cpyext/state.py:128: in build_api self.api_lib = str(api.build_bridge(self.space)) module/cpyext/api.py:1468: in build_bridge builder.attach_all(space) module/cpyext/api.py:1535: in attach_all attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1497: in attach_recursively make_ref(space, w_type)) module/cpyext/pyobject.py:510: in make_ref return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:483: in get_pyobj_and_incref pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: in as_pyobj py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:326: in create_ref track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:375: in track_reference w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:132: in _cpyext_attach_pyobj rawrefcount.create_link_pypy(self, py_obj) ../rpython/rlib/rawrefcount.py:187: in create_link_pypy assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:102: in _ob_link_get return ob.c_ob_pypy_link _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2a6a18d0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _______________ ERROR at setup of TestBytes.test_AsEncodedObject _______________ item = <Function 'test_AsEncodedObject'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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:481: in __init__ self.initialize() objspace/std/objspace.py:118: in initialize self.setup_builtin_modules() interpreter/baseobjspace.py:739: in setup_builtin_modules self.fromcache(State).build_api() module/cpyext/state.py:128: in build_api self.api_lib = str(api.build_bridge(self.space)) module/cpyext/api.py:1468: in build_bridge builder.attach_all(space) module/cpyext/api.py:1535: in attach_all attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1497: in attach_recursively make_ref(space, w_type)) module/cpyext/pyobject.py:510: in make_ref return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:483: in get_pyobj_and_incref pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: in as_pyobj py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:326: in create_ref track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:375: in track_reference w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:132: in _cpyext_attach_pyobj rawrefcount.create_link_pypy(self, py_obj) ../rpython/rlib/rawrefcount.py:187: in create_link_pypy assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:102: in _ob_link_get return ob.c_ob_pypy_link _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2263b230>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _____________________ ERROR at setup of TestBytes.test_eq ______________________ item = <Function 'test_eq'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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:481: in __init__ self.initialize() objspace/std/objspace.py:118: in initialize self.setup_builtin_modules() interpreter/baseobjspace.py:739: in setup_builtin_modules self.fromcache(State).build_api() module/cpyext/state.py:128: in build_api self.api_lib = str(api.build_bridge(self.space)) module/cpyext/api.py:1468: in build_bridge builder.attach_all(space) module/cpyext/api.py:1535: in attach_all attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1497: in attach_recursively make_ref(space, w_type)) module/cpyext/pyobject.py:510: in make_ref return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:483: in get_pyobj_and_incref pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: in as_pyobj py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:326: in create_ref track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:375: in track_reference w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:132: in _cpyext_attach_pyobj rawrefcount.create_link_pypy(self, py_obj) ../rpython/rlib/rawrefcount.py:187: in create_link_pypy assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:102: in _ob_link_get return ob.c_ob_pypy_link _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x28ec3420>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ____________________ ERROR at setup of TestBytes.test_join _____________________ item = <Function 'test_join'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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:481: in __init__ self.initialize() objspace/std/objspace.py:118: in initialize self.setup_builtin_modules() interpreter/baseobjspace.py:739: in setup_builtin_modules self.fromcache(State).build_api() module/cpyext/state.py:128: in build_api self.api_lib = str(api.build_bridge(self.space)) module/cpyext/api.py:1468: in build_bridge builder.attach_all(space) module/cpyext/api.py:1535: in attach_all attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1497: in attach_recursively make_ref(space, w_type)) module/cpyext/pyobject.py:510: in make_ref return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:483: in get_pyobj_and_incref pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: in as_pyobj py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:326: in create_ref track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:375: in track_reference w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:132: in _cpyext_attach_pyobj rawrefcount.create_link_pypy(self, py_obj) ../rpython/rlib/rawrefcount.py:187: in create_link_pypy assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:102: in _ob_link_get return ob.c_ob_pypy_link _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x296351b0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ========================== 20 error in 80.74 seconds =========================== ++ 02:45:02 starting module/cpyext/test/test_eval.py [62 started in total] __ module/cpyext/test/test_datetime.py [59 done in total, somefailed=True] ____ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 16 items module/cpyext/test/test_datetime.py EEEEEEEEEEEEEEEE ==================================== ERRORS ==================================== ___________________ ERROR at setup of TestDatetime.test_date ___________________ item = <Function 'test_date'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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:481: in __init__ self.initialize() objspace/std/objspace.py:118: in initialize self.setup_builtin_modules() interpreter/baseobjspace.py:739: in setup_builtin_modules self.fromcache(State).build_api() module/cpyext/state.py:128: in build_api self.api_lib = str(api.build_bridge(self.space)) module/cpyext/api.py:1468: in build_bridge builder.attach_all(space) module/cpyext/api.py:1535: in attach_all attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1497: in attach_recursively make_ref(space, w_type)) module/cpyext/pyobject.py:510: in make_ref return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:483: in get_pyobj_and_incref pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: in as_pyobj py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:326: in create_ref track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:375: in track_reference w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:132: in _cpyext_attach_pyobj rawrefcount.create_link_pypy(self, py_obj) ../rpython/rlib/rawrefcount.py:187: in create_link_pypy assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:102: in _ob_link_get return ob.c_ob_pypy_link _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x400a59b0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ___________________ ERROR at setup of TestDatetime.test_time ___________________ item = <Function 'test_time'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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:481: in __init__ self.initialize() objspace/std/objspace.py:118: in initialize self.setup_builtin_modules() interpreter/baseobjspace.py:739: in setup_builtin_modules self.fromcache(State).build_api() module/cpyext/state.py:128: in build_api self.api_lib = str(api.build_bridge(self.space)) module/cpyext/api.py:1468: in build_bridge builder.attach_all(space) module/cpyext/api.py:1535: in attach_all attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1497: in attach_recursively make_ref(space, w_type)) module/cpyext/pyobject.py:510: in make_ref return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:483: in get_pyobj_and_incref pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: in as_pyobj py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:326: in create_ref track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:375: in track_reference w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:132: in _cpyext_attach_pyobj rawrefcount.create_link_pypy(self, py_obj) ../rpython/rlib/rawrefcount.py:187: in create_link_pypy assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:102: in _ob_link_get return ob.c_ob_pypy_link _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3bd284e0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _________________ ERROR at setup of TestDatetime.test_datetime _________________ item = <Function 'test_datetime'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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:481: in __init__ self.initialize() objspace/std/objspace.py:118: in initialize self.setup_builtin_modules() interpreter/baseobjspace.py:739: in setup_builtin_modules self.fromcache(State).build_api() module/cpyext/state.py:128: in build_api self.api_lib = str(api.build_bridge(self.space)) module/cpyext/api.py:1468: in build_bridge builder.attach_all(space) module/cpyext/api.py:1535: in attach_all attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1497: in attach_recursively make_ref(space, w_type)) module/cpyext/pyobject.py:510: in make_ref return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:483: in get_pyobj_and_incref pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: in as_pyobj py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:326: in create_ref track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:375: in track_reference w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:132: in _cpyext_attach_pyobj rawrefcount.create_link_pypy(self, py_obj) ../rpython/rlib/rawrefcount.py:187: in create_link_pypy assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:102: in _ob_link_get return ob.c_ob_pypy_link _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3e9160e0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError __________________ ERROR at setup of TestDatetime.test_delta ___________________ item = <Function 'test_delta'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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:481: in __init__ self.initialize() objspace/std/objspace.py:118: in initialize self.setup_builtin_modules() interpreter/baseobjspace.py:739: in setup_builtin_modules self.fromcache(State).build_api() module/cpyext/state.py:128: in build_api self.api_lib = str(api.build_bridge(self.space)) module/cpyext/api.py:1468: in build_bridge builder.attach_all(space) module/cpyext/api.py:1535: in attach_all attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1497: in attach_recursively make_ref(space, w_type)) module/cpyext/pyobject.py:510: in make_ref return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:483: in get_pyobj_and_incref pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: in as_pyobj py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:326: in create_ref track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:375: in track_reference w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:132: in _cpyext_attach_pyobj rawrefcount.create_link_pypy(self, py_obj) ../rpython/rlib/rawrefcount.py:187: in create_link_pypy assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:102: in _ob_link_get return ob.c_ob_pypy_link _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x38adefe0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ______________ ERROR at setup of TestDatetime.test_fromtimestamp _______________ item = <Function 'test_fromtimestamp'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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:481: in __init__ self.initialize() objspace/std/objspace.py:118: in initialize self.setup_builtin_modules() interpreter/baseobjspace.py:739: in setup_builtin_modules self.fromcache(State).build_api() module/cpyext/state.py:128: in build_api self.api_lib = str(api.build_bridge(self.space)) module/cpyext/api.py:1468: in build_bridge builder.attach_all(space) module/cpyext/api.py:1535: in attach_all attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1497: in attach_recursively make_ref(space, w_type)) module/cpyext/pyobject.py:510: in make_ref return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:483: in get_pyobj_and_incref pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: in as_pyobj py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:326: in create_ref track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:375: in track_reference w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:132: in _cpyext_attach_pyobj rawrefcount.create_link_pypy(self, py_obj) ../rpython/rlib/rawrefcount.py:187: in create_link_pypy assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:102: in _ob_link_get return ob.c_ob_pypy_link _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3ffb3f90>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _____________ ERROR at setup of TestDatetime.test_basicsize[Time] ______________ item = <Function 'test_basicsize[Time]'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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:481: in __init__ self.initialize() objspace/std/objspace.py:118: in initialize self.setup_builtin_modules() interpreter/baseobjspace.py:739: in setup_builtin_modules self.fromcache(State).build_api() module/cpyext/state.py:128: in build_api self.api_lib = str(api.build_bridge(self.space)) module/cpyext/api.py:1468: in build_bridge builder.attach_all(space) module/cpyext/api.py:1535: in attach_all attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1497: in attach_recursively make_ref(space, w_type)) module/cpyext/pyobject.py:510: in make_ref return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:483: in get_pyobj_and_incref pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: in as_pyobj py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:326: in create_ref track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:375: in track_reference w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:132: in _cpyext_attach_pyobj rawrefcount.create_link_pypy(self, py_obj) ../rpython/rlib/rawrefcount.py:187: in create_link_pypy assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:102: in _ob_link_get return ob.c_ob_pypy_link _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x40dfe110>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ___________ ERROR at setup of TestDatetime.test_basicsize[DateTime] ____________ item = <Function 'test_basicsize[DateTime]'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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:481: in __init__ self.initialize() objspace/std/objspace.py:118: in initialize self.setup_builtin_modules() interpreter/baseobjspace.py:739: in setup_builtin_modules self.fromcache(State).build_api() module/cpyext/state.py:128: in build_api self.api_lib = str(api.build_bridge(self.space)) module/cpyext/api.py:1468: in build_bridge builder.attach_all(space) module/cpyext/api.py:1535: in attach_all attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1497: in attach_recursively make_ref(space, w_type)) module/cpyext/pyobject.py:510: in make_ref return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:483: in get_pyobj_and_incref pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: in as_pyobj py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:326: in create_ref track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:375: in track_reference w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:132: in _cpyext_attach_pyobj rawrefcount.create_link_pypy(self, py_obj) ../rpython/rlib/rawrefcount.py:187: in create_link_pypy assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:102: in _ob_link_get return ob.c_ob_pypy_link _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3dc4e8a0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _____________ ERROR at setup of TestDatetime.test_basicsize[Date] ______________ item = <Function 'test_basicsize[Date]'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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:481: in __init__ self.initialize() objspace/std/objspace.py:118: in initialize self.setup_builtin_modules() interpreter/baseobjspace.py:739: in setup_builtin_modules self.fromcache(State).build_api() module/cpyext/state.py:128: in build_api self.api_lib = str(api.build_bridge(self.space)) module/cpyext/api.py:1468: in build_bridge builder.attach_all(space) module/cpyext/api.py:1535: in attach_all attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1497: in attach_recursively make_ref(space, w_type)) module/cpyext/pyobject.py:510: in make_ref return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:483: in get_pyobj_and_incref pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: in as_pyobj py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:326: in create_ref track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:375: in track_reference w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:132: in _cpyext_attach_pyobj rawrefcount.create_link_pypy(self, py_obj) ../rpython/rlib/rawrefcount.py:187: in create_link_pypy assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:102: in _ob_link_get return ob.c_ob_pypy_link _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3cc26c50>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _____________ ERROR at setup of TestDatetime.test_basicsize[Delta] _____________ item = <Function 'test_basicsize[Delta]'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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:481: in __init__ self.initialize() objspace/std/objspace.py:118: in initialize self.setup_builtin_modules() interpreter/baseobjspace.py:739: in setup_builtin_modules self.fromcache(State).build_api() module/cpyext/state.py:128: in build_api self.api_lib = str(api.build_bridge(self.space)) module/cpyext/api.py:1468: in build_bridge builder.attach_all(space) module/cpyext/api.py:1535: in attach_all attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1497: in attach_recursively make_ref(space, w_type)) module/cpyext/pyobject.py:510: in make_ref return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:483: in get_pyobj_and_incref pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: in as_pyobj py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:326: in create_ref track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:375: in track_reference w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:132: in _cpyext_attach_pyobj rawrefcount.create_link_pypy(self, py_obj) ../rpython/rlib/rawrefcount.py:187: in create_link_pypy assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:102: in _ob_link_get return ob.c_ob_pypy_link _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3e201250>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _________________ ERROR at setup of AppTestDatetime.test_CAPI __________________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000004234c458>, 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_CAPI'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_CAPI'>} 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 0x00007f44ba713670> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000041b168e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000392b9820>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000392b9860>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_CAPI'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_CAPI'>} 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 0x0000000041b168e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000392b9820>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000392b9860>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_CAPI'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_CAPI'>} 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_CAPI'>, '__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 0x000000004207ede0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...'test_CAPI'>, '__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 0x000000004243e7a0> 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 0x000000004243e7a0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...'test_CAPI'>, '__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_CAPI'>, '__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_CAPI'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x000000004199cd78> key = (((True, True, True, 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 0x000000004199cd78> 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 0x000000004199cd78> 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 0x000000004199cd78> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000004268e460> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000042f41210> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f44bae72e80>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f44bae72ec0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f44bae72ee0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000003c9d4480>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000004199d2f0>, <W_TypeObject 'GenericAlias' at 0x4390f1d8>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x44890cd0> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x44890cd0> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x44890cd0> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x44890cd0> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x409b1920>> w_obj = <W_TypeObject 'ellipsis' at 0x44890cd0> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x44890cd0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x409b1920>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x44890cd0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x409b1920>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x409b1920>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x409b1920>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _____________ ERROR at setup of AppTestDatetime.test_constructors ______________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000004453d100>, 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_constructors'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_constructors'>} 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 0x00007f44ba713670> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000041b168e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000392b9820>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000392b9860>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_constructors'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_constructors'>} 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 0x0000000041b168e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000392b9820>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000392b9860>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_constructors'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_constructors'>} 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_constructors'>, '__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 0x0000000042ae7880> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...nstructors'>, '__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 0x000000004668a560> 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 0x000000004668a560> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...nstructors'>, '__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_constructors'>, '__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_constructors'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x000000004661a790> key = (((True, True, True, 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 0x000000004661a790> 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 0x000000004661a790> 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 0x000000004661a790> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000044d1f9a0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000045f78e58> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f44bae72e80>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f44bae72ec0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f44bae72ee0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000003c9d4480>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000004661ad08>, <W_TypeObject 'GenericAlias' at 0x45cbcd08>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x42d36aa0> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x42d36aa0> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x42d36aa0> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x42d36aa0> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3c414f00>> w_obj = <W_TypeObject 'ellipsis' at 0x42d36aa0> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x42d36aa0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3c414f00>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x42d36aa0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3c414f00>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3c414f00>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3c414f00>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _________ ERROR at setup of AppTestDatetime.test_timezone_constructors _________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000045152098>, 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_timezone_constructors'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_timezone_constructors'>} 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 0x00007f44ba713670> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000041b168e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000392b9820>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000392b9860>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_timezone_constructors'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_timezone_constructors'>} 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 0x0000000041b168e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000392b9820>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000392b9860>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_timezone_constructors'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_timezone_constructors'>} 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_timezone_constructors'>, '__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 0x000000003e17d808> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...nstructors'>, '__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 0x000000004258c120> 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 0x000000004258c120> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...nstructors'>, '__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_timezone_constructors'>, '__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_timezone_constructors'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x00000000439ac608> key = (((True, True, True, 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 0x00000000439ac608> 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 0x00000000439ac608> 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 0x00000000439ac608> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000004287dea0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000444d6a30> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f44bae72e80>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f44bae72ec0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f44bae72ee0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000003c9d4480>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x00000000439ace90>, <W_TypeObject 'GenericAlias' at 0x457554e8>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x41a06ad8> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x41a06ad8> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x41a06ad8> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x41a06ad8> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3e12eb10>> w_obj = <W_TypeObject 'ellipsis' at 0x41a06ad8> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x41a06ad8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3e12eb10>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x41a06ad8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3e12eb10>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3e12eb10>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3e12eb10>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ________________ ERROR at setup of AppTestDatetime.test_macros _________________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x00000000466daf20>, 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_macros'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_macros'>} 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 0x00007f44ba713670> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000041b168e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000392b9820>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000392b9860>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_macros'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_macros'>} 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 0x0000000041b168e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000392b9820>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000392b9860>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_macros'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_macros'>} 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_macros'>, '__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 0x00000000424e6c28> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...est_macros'>, '__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 0x0000000045fa8ea0> 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 0x0000000045fa8ea0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...est_macros'>, '__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_macros'>, '__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_macros'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x0000000045fcf0c0> key = (((True, True, True, 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 0x0000000045fcf0c0> 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 0x0000000045fcf0c0> 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 0x0000000045fcf0c0> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000046576420> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000465628e0> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f44bae72e80>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f44bae72ec0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f44bae72ee0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000003c9d4480>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000045fcf638>, <W_TypeObject 'GenericAlias' at 0x44eb3910>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x456ffb08> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x456ffb08> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x456ffb08> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x456ffb08> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4077af00>> w_obj = <W_TypeObject 'ellipsis' at 0x456ffb08> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x456ffb08>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4077af00>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x456ffb08> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4077af00>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4077af00>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4077af00>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ________________ ERROR at setup of AppTestDatetime.test_tzinfo _________________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000003eef7cb8>, 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_tzinfo'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_tzinfo'>} 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 0x00007f44ba713670> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000041b168e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000392b9820>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000392b9860>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_tzinfo'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_tzinfo'>} 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 0x0000000041b168e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000392b9820>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000392b9860>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_tzinfo'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_tzinfo'>} 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_tzinfo'>, '__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 0x000000003a238e30> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...est_tzinfo'>, '__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 0x000000004037d1a0> 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 0x000000004037d1a0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...est_tzinfo'>, '__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_tzinfo'>, '__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_tzinfo'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x00000000409c3750> key = (((True, True, True, 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 0x00000000409c3750> 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 0x00000000409c3750> 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 0x00000000409c3750> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000040979de0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000003ef7fc20> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f44bae72e80>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f44bae72ec0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f44bae72ee0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000003c9d4480>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x00000000409c3d38>, <W_TypeObject 'GenericAlias' at 0x4285cc98>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x41ae5fa0> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x41ae5fa0> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x41ae5fa0> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x41ae5fa0> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4058db00>> w_obj = <W_TypeObject 'ellipsis' at 0x41ae5fa0> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x41ae5fa0>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4058db00>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x41ae5fa0> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4058db00>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4058db00>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x4058db00>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ________________ ERROR at setup of AppTestDatetime.test_checks _________________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x00000000423deb60>, 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_checks'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_checks'>} 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 0x00007f44ba713670> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000041b168e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000392b9820>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000392b9860>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_checks'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_checks'>} 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 0x0000000041b168e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000392b9820>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000392b9860>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_checks'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_checks'>} 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_checks'>, '__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 0x000000003f245268> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...est_checks'>, '__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 0x000000004506e8e0> 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 0x000000004506e8e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...est_checks'>, '__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_checks'>, '__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_checks'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x0000000046194fa8> key = (((True, True, True, 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 0x0000000046194fa8> 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 0x0000000046194fa8> 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 0x0000000046194fa8> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000044f076a0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000045f72598> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f44bae72e80>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f44bae72ec0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f44bae72ee0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000003c9d4480>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x000000004613d2f0>, <W_TypeObject 'GenericAlias' at 0x4141d2f0>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4119d558> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4119d558> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4119d558> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x4119d558> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3e8c69b0>> w_obj = <W_TypeObject 'ellipsis' at 0x4119d558> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x4119d558>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3e8c69b0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x4119d558> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3e8c69b0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3e8c69b0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3e8c69b0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _________________ ERROR at setup of AppTestDatetime.test_misc __________________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000003f59cdb8>, 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_misc'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_misc'>} 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 0x00007f44ba713670> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000041b168e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000392b9820>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000392b9860>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_misc'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_misc'>} 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 0x0000000041b168e0>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x00000000392b9820>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x00000000392b9860>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_misc'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_misc'>} 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_misc'>, '__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 0x00000000477213f8> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...'test_misc'>, '__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 0x0000000047753aa0> 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 0x0000000047753aa0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...'test_misc'>, '__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_misc'>, '__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_misc'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x00000000477578d8> key = (((True, True, True, 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 0x00000000477578d8> 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 0x00000000477578d8> 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 0x00000000477578d8> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000042c11920> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000044a15d70> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f44bae72e80>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f44bae72ec0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f44bae72ee0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000003c9d4480>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000047757e50>, <W_TypeObject 'GenericAlias' at 0x3e93bde0>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3eaf3868> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3eaf3868> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3eaf3868> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3eaf3868> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x403f2720>> w_obj = <W_TypeObject 'ellipsis' at 0x3eaf3868> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x3eaf3868>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x403f2720>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x3eaf3868> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x403f2720>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x403f2720>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x403f2720>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ========================== 16 error in 65.90 seconds =========================== ++ 02:45:57 starting module/cpyext/test/test_exception.py [63 started in total] __ module/cpyext/test/test_dictobject.py [60 done in total, somefailed=True] __ ============================= test session starts ============================== platform linux2 -- Python 2.7.18[pypy-7.3.22-final], pytest-2.9.2, py-1.4.29, pluggy-0.3.1 hypothesis profile 'default' -> deadline=None, database=DirectoryBasedExampleDatabase('/buildbot/slave/own-linux-x86-64/build/pypy/.hypothesis/examples') pytest-2.9.2 from /buildbot/slave/own-linux-x86-64/build/pytest.pyc rootdir: /buildbot/slave/own-linux-x86-64/build, inifile: pytest.ini plugins: hypothesis-4.39.3 collected 19 items module/cpyext/test/test_dictobject.py EEEEEEEEEEEEEEEEEEE ==================================== ERRORS ==================================== __________________ ERROR at setup of TestDictObject.test_dict __________________ item = <Function 'test_dict'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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:481: in __init__ self.initialize() objspace/std/objspace.py:118: in initialize self.setup_builtin_modules() interpreter/baseobjspace.py:739: in setup_builtin_modules self.fromcache(State).build_api() module/cpyext/state.py:128: in build_api self.api_lib = str(api.build_bridge(self.space)) module/cpyext/api.py:1468: in build_bridge builder.attach_all(space) module/cpyext/api.py:1535: in attach_all attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1497: in attach_recursively make_ref(space, w_type)) module/cpyext/pyobject.py:510: in make_ref return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:483: in get_pyobj_and_incref pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: in as_pyobj py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:326: in create_ref track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:375: in track_reference w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:132: in _cpyext_attach_pyobj rawrefcount.create_link_pypy(self, py_obj) ../rpython/rlib/rawrefcount.py:187: in create_link_pypy assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:102: in _ob_link_get return ob.c_ob_pypy_link _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x31529d50>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _________________ ERROR at setup of TestDictObject.test_check __________________ item = <Function 'test_check'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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:481: in __init__ self.initialize() objspace/std/objspace.py:118: in initialize self.setup_builtin_modules() interpreter/baseobjspace.py:739: in setup_builtin_modules self.fromcache(State).build_api() module/cpyext/state.py:128: in build_api self.api_lib = str(api.build_bridge(self.space)) module/cpyext/api.py:1468: in build_bridge builder.attach_all(space) module/cpyext/api.py:1535: in attach_all attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1497: in attach_recursively make_ref(space, w_type)) module/cpyext/pyobject.py:510: in make_ref return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:483: in get_pyobj_and_incref pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: in as_pyobj py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:326: in create_ref track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:375: in track_reference w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:132: in _cpyext_attach_pyobj rawrefcount.create_link_pypy(self, py_obj) ../rpython/rlib/rawrefcount.py:187: in create_link_pypy assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:102: in _ob_link_get return ob.c_ob_pypy_link _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x30cd4660>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError __________________ ERROR at setup of TestDictObject.test_keys __________________ item = <Function 'test_keys'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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:481: in __init__ self.initialize() objspace/std/objspace.py:118: in initialize self.setup_builtin_modules() interpreter/baseobjspace.py:739: in setup_builtin_modules self.fromcache(State).build_api() module/cpyext/state.py:128: in build_api self.api_lib = str(api.build_bridge(self.space)) module/cpyext/api.py:1468: in build_bridge builder.attach_all(space) module/cpyext/api.py:1535: in attach_all attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1497: in attach_recursively make_ref(space, w_type)) module/cpyext/pyobject.py:510: in make_ref return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:483: in get_pyobj_and_incref pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: in as_pyobj py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:326: in create_ref track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:375: in track_reference w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:132: in _cpyext_attach_pyobj rawrefcount.create_link_pypy(self, py_obj) ../rpython/rlib/rawrefcount.py:187: in create_link_pypy assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:102: in _ob_link_get return ob.c_ob_pypy_link _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2f96d590>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _________________ ERROR at setup of TestDictObject.test_merge __________________ item = <Function 'test_merge'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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:481: in __init__ self.initialize() objspace/std/objspace.py:118: in initialize self.setup_builtin_modules() interpreter/baseobjspace.py:739: in setup_builtin_modules self.fromcache(State).build_api() module/cpyext/state.py:128: in build_api self.api_lib = str(api.build_bridge(self.space)) module/cpyext/api.py:1468: in build_bridge builder.attach_all(space) module/cpyext/api.py:1535: in attach_all attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1497: in attach_recursively make_ref(space, w_type)) module/cpyext/pyobject.py:510: in make_ref return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:483: in get_pyobj_and_incref pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: in as_pyobj py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:326: in create_ref track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:375: in track_reference w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:132: in _cpyext_attach_pyobj rawrefcount.create_link_pypy(self, py_obj) ../rpython/rlib/rawrefcount.py:187: in create_link_pypy assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:102: in _ob_link_get return ob.c_ob_pypy_link _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2d3e44e0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _________________ ERROR at setup of TestDictObject.test_update _________________ item = <Function 'test_update'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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:481: in __init__ self.initialize() objspace/std/objspace.py:118: in initialize self.setup_builtin_modules() interpreter/baseobjspace.py:739: in setup_builtin_modules self.fromcache(State).build_api() module/cpyext/state.py:128: in build_api self.api_lib = str(api.build_bridge(self.space)) module/cpyext/api.py:1468: in build_bridge builder.attach_all(space) module/cpyext/api.py:1535: in attach_all attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1497: in attach_recursively make_ref(space, w_type)) module/cpyext/pyobject.py:510: in make_ref return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:483: in get_pyobj_and_incref pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: in as_pyobj py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:326: in create_ref track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:375: in track_reference w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:132: in _cpyext_attach_pyobj rawrefcount.create_link_pypy(self, py_obj) ../rpython/rlib/rawrefcount.py:187: in create_link_pypy assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:102: in _ob_link_get return ob.c_ob_pypy_link _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2fd6f400>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError __ ERROR at setup of TestDictObject.test_update_doesnt_accept_list_of_tuples ___ item = <Function 'test_update_doesnt_accept_list_of_tuples'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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:481: in __init__ self.initialize() objspace/std/objspace.py:118: in initialize self.setup_builtin_modules() interpreter/baseobjspace.py:739: in setup_builtin_modules self.fromcache(State).build_api() module/cpyext/state.py:128: in build_api self.api_lib = str(api.build_bridge(self.space)) module/cpyext/api.py:1468: in build_bridge builder.attach_all(space) module/cpyext/api.py:1535: in attach_all attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1497: in attach_recursively make_ref(space, w_type)) module/cpyext/pyobject.py:510: in make_ref return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:483: in get_pyobj_and_incref pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: in as_pyobj py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:326: in create_ref track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:375: in track_reference w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:132: in _cpyext_attach_pyobj rawrefcount.create_link_pypy(self, py_obj) ../rpython/rlib/rawrefcount.py:187: in create_link_pypy assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:102: in _ob_link_get return ob.c_ob_pypy_link _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2eba75a0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _______________ ERROR at setup of TestDictObject.test_dictproxy ________________ item = <Function 'test_dictproxy'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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:481: in __init__ self.initialize() objspace/std/objspace.py:118: in initialize self.setup_builtin_modules() interpreter/baseobjspace.py:739: in setup_builtin_modules self.fromcache(State).build_api() module/cpyext/state.py:128: in build_api self.api_lib = str(api.build_bridge(self.space)) module/cpyext/api.py:1468: in build_bridge builder.attach_all(space) module/cpyext/api.py:1535: in attach_all attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1497: in attach_recursively make_ref(space, w_type)) module/cpyext/pyobject.py:510: in make_ref return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:483: in get_pyobj_and_incref pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: in as_pyobj py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:326: in create_ref track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:375: in track_reference w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:132: in _cpyext_attach_pyobj rawrefcount.create_link_pypy(self, py_obj) ../rpython/rlib/rawrefcount.py:187: in create_link_pypy assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:102: in _ob_link_get return ob.c_ob_pypy_link _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2a06d6b0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _______________ ERROR at setup of TestDictObject.test_typedict1 ________________ item = <Function 'test_typedict1'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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:481: in __init__ self.initialize() objspace/std/objspace.py:118: in initialize self.setup_builtin_modules() interpreter/baseobjspace.py:739: in setup_builtin_modules self.fromcache(State).build_api() module/cpyext/state.py:128: in build_api self.api_lib = str(api.build_bridge(self.space)) module/cpyext/api.py:1468: in build_bridge builder.attach_all(space) module/cpyext/api.py:1535: in attach_all attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1497: in attach_recursively make_ref(space, w_type)) module/cpyext/pyobject.py:510: in make_ref return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:483: in get_pyobj_and_incref pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: in as_pyobj py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:326: in create_ref track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:375: in track_reference w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:132: in _cpyext_attach_pyobj rawrefcount.create_link_pypy(self, py_obj) ../rpython/rlib/rawrefcount.py:187: in create_link_pypy assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:102: in _ob_link_get return ob.c_ob_pypy_link _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3169b460>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ____________ ERROR at setup of AppTestDictObject.test_dictproxytype ____________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x00000000335f59e8>, 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_dictproxytype'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_dictproxytype'>} 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 0x00007f571e115248> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000032caa420>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002a8c3120>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002a8c3160>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_dictproxytype'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_dictproxytype'>} 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 0x0000000032caa420>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002a8c3120>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002a8c3160>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_dictproxytype'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_dictproxytype'>} 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_dictproxytype'>, '__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 0x00000000312fd9e8> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...tproxytype'>, '__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 0x0000000031749a60> 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 0x0000000031749a60> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...tproxytype'>, '__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_dictproxytype'>, '__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_dictproxytype'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x00000000324ef948> key = (((True, True, True, 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 0x00000000324ef948> 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 0x00000000324ef948> 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 0x00000000324ef948> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000031fd7220> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000032b582f8> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f5722be6e80>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f5722be6ec0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f5722be6ee0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000002c502c28>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x00000000324efec0>, <W_TypeObject 'GenericAlias' at 0x347172f0>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x348b52b8> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x348b52b8> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x348b52b8> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x348b52b8> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2eb65a50>> w_obj = <W_TypeObject 'ellipsis' at 0x348b52b8> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x348b52b8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2eb65a50>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x348b52b8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2eb65a50>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2eb65a50>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2eb65a50>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError __________ ERROR at setup of AppTestDictObject.test_getitemwitherror ___________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x000000002a5611f0>, 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_getitemwitherror'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_getitemwitherror'>} 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 0x00007f571e115248> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000032caa420>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002a8c3120>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002a8c3160>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_getitemwitherror'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_getitemwitherror'>} 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 0x0000000032caa420>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002a8c3120>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002a8c3160>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_getitemwitherror'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_getitemwitherror'>} 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_getitemwitherror'>, '__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 0x0000000035550cc8> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...mwitherror'>, '__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 0x0000000035af3160> 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 0x0000000035af3160> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...mwitherror'>, '__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_getitemwitherror'>, '__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_getitemwitherror'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x0000000034d32090> key = (((True, True, True, 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 0x0000000034d32090> 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 0x0000000034d32090> 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 0x0000000034d32090> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000003446f9e0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000034a9f2f0> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f5722be6e80>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f5722be6ec0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f5722be6ee0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000002c502c28>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000034d32608>, <W_TypeObject 'GenericAlias' at 0x3629a1a8>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x362c2020> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x362c2020> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x362c2020> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x362c2020> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2eb60e20>> w_obj = <W_TypeObject 'ellipsis' at 0x362c2020> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x362c2020>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2eb60e20>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x362c2020> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2eb60e20>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2eb60e20>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2eb60e20>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _____________ ERROR at setup of AppTestDictObject.test_setdefault ______________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000033cea5c0>, 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_setdefault'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_setdefault'>} 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 0x00007f571e115248> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000032caa420>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002a8c3120>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002a8c3160>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_setdefault'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_setdefault'>} 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 0x0000000032caa420>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002a8c3120>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002a8c3160>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_setdefault'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_setdefault'>} 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_setdefault'>, '__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 0x000000002fdd7bc8> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...setdefault'>, '__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 0x000000002fc7b2e0> 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 0x000000002fc7b2e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...setdefault'>, '__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_setdefault'>, '__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_setdefault'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x000000003034be88> key = (((True, True, True, 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 0x000000003034be88> 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 0x000000003034be88> 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 0x000000003034be88> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000030048260> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000307f90c0> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f5722be6e80>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f5722be6ec0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f5722be6ee0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000002c502c28>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000003035a4b8>, <W_TypeObject 'GenericAlias' at 0x30af5018>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x32aa7050> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x32aa7050> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x32aa7050> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x32aa7050> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2d9ae320>> w_obj = <W_TypeObject 'ellipsis' at 0x32aa7050> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x32aa7050>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2d9ae320>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x32aa7050> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2d9ae320>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2d9ae320>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2d9ae320>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _______________ ERROR at setup of AppTestDictObject.test_update ________________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000035518548>, 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_update'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_update'>} 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 0x00007f571e115248> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000032caa420>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002a8c3120>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002a8c3160>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_update'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_update'>} 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 0x0000000032caa420>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002a8c3120>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002a8c3160>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_update'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_update'>} 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_update'>, '__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 0x0000000032a8e5c0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...est_update'>, '__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 0x0000000035fd9060> 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 0x0000000035fd9060> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...est_update'>, '__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_update'>, '__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_update'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x000000003658d3d0> key = (((True, True, True, 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 0x000000003658d3d0> 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 0x000000003658d3d0> 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 0x000000003658d3d0> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000034b674e0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000003614b4b0> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f5722be6e80>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f5722be6ec0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f5722be6ee0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000002c502c28>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000003658d948>, <W_TypeObject 'GenericAlias' at 0x3424d7c0>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x341e8838> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x341e8838> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x341e8838> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x341e8838> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3240dea0>> w_obj = <W_TypeObject 'ellipsis' at 0x341e8838> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x341e8838>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3240dea0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x341e8838> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3240dea0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3240dea0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x3240dea0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ________________ ERROR at setup of AppTestDictObject.test_iter _________________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000038277a60>, 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'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_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 0x00007f571e115248> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000032caa420>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002a8c3120>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002a8c3160>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_iter'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_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 0x0000000032caa420>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002a8c3120>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002a8c3160>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_iter'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_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'>, '__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 0x0000000033822d40> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...'test_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 0x00000000384b8460> 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 0x00000000384b8460> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...'test_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'>, '__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'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x0000000038483718> key = (((True, True, True, 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 0x0000000038483718> 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 0x0000000038483718> 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 0x0000000038483718> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x00000000378091a0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000002f4a38d8> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f5722be6e80>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f5722be6ec0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f5722be6ee0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000002c502c28>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000038483c90>, <W_TypeObject 'GenericAlias' at 0x30153a98>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3018b6a8> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3018b6a8> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3018b6a8> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x3018b6a8> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2cb8a4b0>> w_obj = <W_TypeObject 'ellipsis' at 0x3018b6a8> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x3018b6a8>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2cb8a4b0>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x3018b6a8> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2cb8a4b0>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2cb8a4b0>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2cb8a4b0>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ______________ ERROR at setup of AppTestDictObject.test_iterkeys _______________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000035941cb8>, 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_iterkeys'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_iterkeys'>} 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 0x00007f571e115248> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000032caa420>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002a8c3120>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002a8c3160>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_iterkeys'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_iterkeys'>} 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 0x0000000032caa420>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002a8c3120>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002a8c3160>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_iterkeys'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_iterkeys'>} 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_iterkeys'>, '__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 0x000000002fba0778> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_iterkeys'>, '__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 0x000000003406b720> 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 0x000000003406b720> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_iterkeys'>, '__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_iterkeys'>, '__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_iterkeys'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x0000000034434758> key = (((True, True, True, 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 0x0000000034434758> 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 0x0000000034434758> 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 0x0000000034434758> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x000000003409d760> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x0000000034a35910> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f5722be6e80>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f5722be6ec0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f5722be6ee0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000002c502c28>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000034450db0>, <W_TypeObject 'GenericAlias' at 0x37cca640>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x365da838> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x365da838> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x365da838> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x365da838> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x31b6b870>> w_obj = <W_TypeObject 'ellipsis' at 0x365da838> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x365da838>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x31b6b870>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x365da838> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x31b6b870>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x31b6b870>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x31b6b870>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ______________ ERROR at setup of AppTestDictObject.test_typedict2 ______________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000038276a70>, 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_typedict2'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_typedict2'>} 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 0x00007f571e115248> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000032caa420>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002a8c3120>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002a8c3160>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_typedict2'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_typedict2'>} 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 0x0000000032caa420>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002a8c3120>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002a8c3160>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_typedict2'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_typedict2'>} 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_typedict2'>, '__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 0x000000003342cfe8> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._typedict2'>, '__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 0x000000003701a3e0> 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 0x000000003701a3e0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i..._typedict2'>, '__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_typedict2'>, '__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_typedict2'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x0000000037043750> key = (((True, True, True, 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 0x0000000037043750> 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 0x0000000037043750> 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 0x0000000037043750> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000037afed60> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000003824acd0> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f5722be6e80>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f5722be6ec0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f5722be6ee0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000002c502c28>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x000000003782d2b8>, <W_TypeObject 'GenericAlias' at 0x379cb520>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x37485c58> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x37485c58> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x37485c58> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x37485c58> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2efc6100>> w_obj = <W_TypeObject 'ellipsis' at 0x37485c58> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x37485c58>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2efc6100>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x37485c58> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2efc6100>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2efc6100>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2efc6100>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ______________ ERROR at setup of AppTestDictObject.test_advanced _______________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000030a7aae8>, 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_advanced'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_advanced'>} 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 0x00007f571e115248> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000032caa420>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002a8c3120>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002a8c3160>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_advanced'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_advanced'>} 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 0x0000000032caa420>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002a8c3120>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002a8c3160>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_advanced'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_advanced'>} 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_advanced'>, '__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 0x00000000359f4c00> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_advanced'>, '__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 0x00000000338cf220> 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 0x00000000338cf220> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...t_advanced'>, '__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_advanced'>, '__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_advanced'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x00000000351e3248> key = (((True, True, True, 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 0x00000000351e3248> 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 0x00000000351e3248> 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 0x00000000351e3248> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x00000000338e9de0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000354ef2f0> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f5722be6e80>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f5722be6ec0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f5722be6ee0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000002c502c28>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x00000000351ec988>, <W_TypeObject 'GenericAlias' at 0x35d2bf68>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x365caf70> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x365caf70> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x365caf70> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x365caf70> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2adef950>> w_obj = <W_TypeObject 'ellipsis' at 0x365caf70> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x365caf70>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2adef950>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x365caf70> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2adef950>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2adef950>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2adef950>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError _____________ ERROR at setup of AppTestDictObject.test_subclassing _____________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000035940f20>, 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_subclassing'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_subclassing'>} 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 0x00007f571e115248> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000032caa420>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002a8c3120>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002a8c3160>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_subclassing'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_subclassing'>} 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 0x0000000032caa420>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002a8c3120>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002a8c3160>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_subclassing'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_subclassing'>} 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_subclassing'>, '__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 0x000000002ec87970> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ubclassing'>, '__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 0x0000000033218fe0> 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 0x0000000033218fe0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...ubclassing'>, '__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_subclassing'>, '__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_subclassing'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x0000000033202d08> key = (((True, True, True, 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 0x0000000033202d08> 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 0x0000000033202d08> 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 0x0000000033202d08> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x00000000365100e0> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x00000000346f10f8> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f5722be6e80>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f5722be6ec0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f5722be6ee0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000002c502c28>, W_BoolObject(True), W_BoolObject(False), <p...8>, <pypy.interpreter.special.Ellipsis object at 0x0000000033203280>, <W_TypeObject 'GenericAlias' at 0x35d36170>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x35d33d38> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x35d33d38> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x35d33d38> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x35d33d38> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x33df6720>> w_obj = <W_TypeObject 'ellipsis' at 0x35d33d38> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x35d33d38>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x33df6720>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x35d33d38> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x33df6720>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x33df6720>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x33df6720>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ____________ ERROR at setup of AppTestDictObject.test_getitem_error ____________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x00000000372da110>, 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_getitem_error'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_getitem_error'>} 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 0x00007f571e115248> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookImpl instance at 0x0000000032caa420>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002a8c3120>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002a8c3160>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_getitem_error'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_getitem_error'>} 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 0x0000000032caa420>, <_pytest.vendored_packages.pluggy.HookImp...y.HookImpl instance at 0x000000002a8c3120>, <_pytest.vendored_packages.pluggy.HookImpl instance at 0x000000002a8c3160>] kwargs = {'__multicall__': <_MultiCall 0 results, 5 meths, kwargs={'item': <AppTestMethod 'test_getitem_error'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_getitem_error'>} 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_getitem_error'>, '__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 0x0000000037f4c1d8> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...item_error'>, '__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 0x0000000038bfbca0> 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 0x0000000038bfbca0> func = <bound method _MultiCall.execute of <_MultiCall 0 results, 5 meths, kwargs={'i...item_error'>, '__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_getitem_error'>, '__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_getitem_error'> @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:259: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ kwds = {'objspace.disable_entrypoints_in_cffi': True, 'objspace.std.withspecialisedtuple': True, 'usemodules': ['cpyext', 'thread', 'struct', 'array', 'itertools', 'time', ...]} config = <rpython.config.config.Config object at 0x0000000038c07e18> key = (((True, True, True, 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 0x0000000038c07e18> 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 0x0000000038c07e18> 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 0x0000000038c07e18> @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:481: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 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() # final setup > self.setup_builtin_modules() objspace/std/objspace.py:118: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = StdObjSpace @not_rpython def setup_builtin_modules(self): "only for initializing the space." if self.config.objspace.usemodules.cpyext: # Special-case this to have state.install_dll() called early, which # is required to initialise sys on Windows. from pypy.module.cpyext.state import State > self.fromcache(State).build_api() interpreter/baseobjspace.py:739: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.state.State instance at 0x0000000037f79c20> def build_api(self): """NOT_RPYTHON This function is called when at object space creation, and drives the compilation of the cpyext library """ self.setup_rawrefcount() from pypy.module.cpyext import api if not self.space.config.translating: > self.api_lib = str(api.build_bridge(self.space)) module/cpyext/state.py:128: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace def build_bridge(space): "NOT_RPYTHON" from rpython.translator.c.database import LowLevelDatabase use_micronumpy = setup_micronumpy(space) db = LowLevelDatabase() prefix = 'cpyexttest' generate_decls_and_callbacks(db, prefix=prefix) # Structure declaration code functions = [] members = [] structindex = {} for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): functions.append(func.get_ctypes_impl(name, db)) members.append(func.get_ptr_decl(name, db)) structindex[name] = len(structindex) structmembers = '\n'.join(members) struct_declaration_code = """\ struct PyPyAPI { %(members)s } _pypyAPI; RPY_EXTERN struct PyPyAPI* pypyAPI; struct PyPyAPI* pypyAPI = &_pypyAPI; """ % dict(members=structmembers) prologue = ("#include <Python.h>\n" + "#include <structmember.h>\n" + "#include <marshal.h>\n" + "#include <pycore_namespace.h>\n" + ("#include <pypy_numpy.h>\n" if use_micronumpy else "") + "#include <src/thread.c>\n") code = (prologue + struct_declaration_code + '\n' + '\n'.join(functions)) eci = build_eci(code, use_micronumpy, translating=False) eci = eci.compile_shared_lib( outputfilename=str(udir / "module_cache" / "pypyapi"), symbolic=True) space.fromcache(State).install_dll(eci) modulename = py.path.local(eci.libraries[-1]) attach_c_functions(space, eci, prefix) run_bootstrap_functions(space) # load the bridge, and init structure bridge = ctypes.CDLL(str(modulename), mode=ctypes.RTLD_GLOBAL) # populate static data builder = space.fromcache(State).builder = TestingObjBuilder() from pypy.module import cpyext # for the eval() below for name, (typ, expr) in GLOBALS.iteritems(): if '#' in name: name, header = name.split('#') assert typ in ('PyObject*', 'PyTypeObject*', 'PyIntObject*') isptr = False elif name.startswith('PyExc_'): isptr = False elif typ == 'PyDateTime_CAPI*': isptr = True else: raise ValueError("Unknown static data: %s %s" % (typ, name)) w_obj = eval(expr) INTERPLEVEL_API[name] = w_obj mname = mangle_name(prefix, name) if isptr: assert typ == 'PyDateTime_CAPI*' value = w_obj ptr = ctypes.c_void_p.in_dll(bridge, mname) ptr.value = ctypes.cast(ll2ctypes.lltype2ctypes(value), ctypes.c_void_p).value elif typ in ('PyObject*', 'PyTypeObject*'): if name.startswith('PyExc_'): # we already have the pointer in_dll = ll2ctypes.get_ctypes_type(PyObject).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, in_dll) else: # we have a structure, get its address in_dll = ll2ctypes.get_ctypes_type(PyObject.TO).in_dll(bridge, mname) py_obj = ll2ctypes.ctypes2lltype(PyObject, ctypes.pointer(in_dll)) builder.prepare(py_obj, w_obj) pypyAPI = ctypes.POINTER(ctypes.c_void_p).in_dll(bridge, 'pypyAPI') # implement structure initialization code for header, header_functions in FUNCTIONS_BY_HEADER.iteritems(): for name, func in header_functions.iteritems(): pypyAPI[structindex[name]] = ctypes.cast( ll2ctypes.lltype2ctypes(func.get_llhelper(space)), ctypes.c_void_p) # we need to call this *after* the init code above, because it might # indirectly call some functions which are attached to pypyAPI (e.g., we # if do tuple_attach of the prebuilt empty tuple, we need to call # _PyPy_Malloc) > builder.attach_all(space) module/cpyext/api.py:1468: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <pypy.module.cpyext.api.TestingObjBuilder object at 0x000000002bcdfc58> space = StdObjSpace def attach_all(self, space): # this is RPython, called once in pypy-c when it imports cpyext from pypy.module.cpyext.typeobject import finish_type_1, finish_type_2 from pypy.module.cpyext.pyobject import track_static_reference # static_pyobjs = self.get_static_pyobjs() static_objs_w = self.static_objs_w # Static objects are immortal and exempt from the ob_pypy_link prefix: they # are mapped out-of-band (constant tables + _Py_IMMORTAL_REFCNT) rather # than rawrefcount-linked. See rawrefcount.rst. for i in range(len(static_objs_w)): track_static_reference(space, static_pyobjs[i], static_objs_w[i]) # self.cpyext_type_init = [] attached_objs = [] for i in range(len(static_objs_w)): > attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i) module/cpyext/api.py:1535: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace static_pyobjs = [<* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f5722be6e80>>, <* <C object Struct _object { c_ob_refcnt...fcnt, c_ob_type } at 0x7f5722be6ec0>>, <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x7f5722be6ee0>>, ...] static_objs_w = [<pypy.objspace.std.noneobject.W_NoneObject object at 0x000000002c502c28>, W_BoolObject(True), W_BoolObject(False), <p...0>, <pypy.interpreter.special.Ellipsis object at 0x0000000037f563d8>, <W_TypeObject 'GenericAlias' at 0x30141520>, ...] attached_objs = [0, 1, 2, 3], i = 4 def attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, i): # Start at i but make sure all the base classes are already attached from pypy.module.cpyext.pyobject import get_typedescr, make_ref if i in attached_objs: return py_obj = static_pyobjs[i] w_obj = static_objs_w[i] w_base = None # w_obj can be NotImplemented, which is not a W_TypeObject if isinstance(w_obj, W_TypeObject): bases_w = w_obj.bases_w if bases_w: w_base = find_best_base(bases_w) if w_base: try: j = static_objs_w.index(w_base) except ValueError: j = -1 if j >=0 and j not in attached_objs: attach_recursively(space, static_pyobjs, static_objs_w, attached_objs, j) w_type = space.type(w_obj) typedescr = get_typedescr(w_type.layout.typedef) py_obj.c_ob_type = rffi.cast(PyTypeObjectPtr, > make_ref(space, w_type)) module/cpyext/api.py:1497: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x301ba058> w_userdata = None, immortal = False def make_ref(space, w_obj, w_userdata=None, immortal=False): """Turn the W_Root into a corresponding PyObject. You should decref the returned PyObject later. Note that it is often the case, but not guaranteed, that make_ref() returns always the same PyObject for the same W_Root; for example, integers. """ assert not is_pyobj(w_obj) if False and w_obj is not None and space.type(w_obj) is space.w_int: # XXX: adapt for pypy3 state = space.fromcache(State) intval = space.int_w(w_obj) return state.ccall("PyLong_FromLong", intval) > return get_pyobj_and_incref(space, w_obj, w_userdata, immortal=False) module/cpyext/pyobject.py:510: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x301ba058> w_userdata = None, immortal = False def get_pyobj_and_incref(space, w_obj, w_userdata=None, immortal=False): > pyobj = as_pyobj(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:483: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x301ba058> w_userdata = None, immortal = False @jit.dont_look_inside def as_pyobj(space, w_obj, w_userdata=None, immortal=False): """ Returns a 'PyObject *' representing the given interpreter object. This doesn't give a new reference, but the returned 'PyObject *' is valid at least as long as 'w_obj' is. **To be safe, you should use keepalive_until_here(w_obj) some time later.** In case of doubt, use the safer make_ref(). """ assert not is_pyobj(w_obj) if w_obj is not None: py_obj = w_obj._cpyext_as_pyobj(space) if not py_obj: > py_obj = create_ref(space, w_obj, w_userdata, immortal=immortal) module/cpyext/pyobject.py:445: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace, w_obj = <W_TypeObject 'ellipsis' at 0x301ba058> w_userdata = None, immortal = False @jit.dont_look_inside def create_ref(space, w_obj, w_userdata=None, immortal=False): """ Allocates a PyObject, and fills its fields with info from the given interpreter object. """ w_type = space.type(w_obj) pytype = rffi.cast(PyTypeObjectPtr, as_pyobj(space, w_type)) typedescr = get_typedescr(w_obj.typedef) if space.is_w(w_type, space.w_text): # These PyUnicodeObjects will always take the compact form # since they come from uint8-encoded strings, so we must # override the default tp_itemsize (see also unicode_alloc) # Maybe this snippet should use the ptype.tp_alloc to allocate the py_obj? itemsize = 1 elif space.is_w(w_type, space.w_type): # Subclasses of "type" (which has space for PyMemberDef) do not # need space for tp_member like heap types do itemsize = 0 else: itemsize = pytype.c_tp_itemsize if itemsize != 0 or space.issubtype_w(w_type, space.w_list): # PyBytesObject, compact PyUnicodeObject and subclasses try: # Can cause infinite recursion if w_obj.__len__ is a c function # so the call will try to convert w_obj to a pyobj via create_ref from pypy.objspace.std.listobject import W_ListObject if isinstance(w_obj, W_ListObject): itemcount = w_obj.length() else: itemcount = space.len_w(w_obj) except OperationError as e: if e.match(space, space.w_TypeError): # issue 4013: is this correct? itemcount = 0 # raise oefmt(space.w_SystemError, # "cpyext: Failure to allocate '%N' (with a non-zero " # "tp_itemsize) when len(obj) cannot be calculated", # w_type) else: raise else: itemcount = 0 py_obj = typedescr.allocate(space, w_type, itemcount=itemcount, immortal=immortal) > track_reference(space, py_obj, w_obj) module/cpyext/pyobject.py:326: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2a290150>> w_obj = <W_TypeObject 'ellipsis' at 0x301ba058> def track_reference(space, py_obj, w_obj): """ Ties py_obj's prefix (marked by refcnt >= REFCNT_FROM_PYPY) to w_obj. A foreign py_obj (below the tag, no prefix) is left unlinked. """ # XXX looks like a PyObject_GC_TRACK if py_obj.c_ob_refcnt >= rawrefcount.REFCNT_FROM_PYPY: > w_obj._cpyext_attach_pyobj(space, py_obj) module/cpyext/pyobject.py:375: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <W_TypeObject 'ellipsis' at 0x301ba058>, space = StdObjSpace py_obj = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2a290150>> def _cpyext_attach_pyobj(self, space, py_obj): self._cpy_ref = py_obj > rawrefcount.create_link_pypy(self, py_obj) module/cpyext/pyobject.py:132: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ p = <W_TypeObject 'ellipsis' at 0x301ba058> ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2a290150>> @not_rpython def create_link_pypy(p, ob): "a link where the PyPy object contains some or all the data" #print 'create_link_pypy\n\t%s\n\t%s' % (p, ob) assert p not in _pypy2ob assert ob._obj not in _pypy2ob_rev > assert not _ob_link_get(ob) ../rpython/rlib/rawrefcount.py:187: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ob = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2a290150>> def _ob_link_get(ob): > return ob.c_ob_pypy_link ../rpython/rlib/rawrefcount.py:102: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <* <C object Struct _object { c_ob_refcnt, c_ob_type } at 0x2a290150>> field_name = 'c_ob_pypy_link' def __getattr__(self, field_name): # ! can only return basic or ptr ! if isinstance(self._T, Struct): if field_name in self._T._flds: o = self._obj._getattr(field_name) return self._expose(field_name, o) try: return self._lookup_adtmeth(field_name) except AttributeError: raise AttributeError("%r instance has no field %r" % (self._T, > field_name)) E AttributeError: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link' ../rpython/rtyper/lltypesystem/lltype.py:1270: AttributeError ______________ ERROR at setup of AppTestDictObject.test_contains _______________ self = <CallInfo when='setup' exception: <Struct _object { c_ob_refcnt, c_ob_type }> instance has no field 'c_ob_pypy_link'> func = <function <lambda> at 0x0000000038511d30>, 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_contains'>, '__multicall__': <_MultiCall 0 results, 5 meths, kwargs={...}>}>, 'item': <AppTestMethod 'test_contains'>} 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 0x00007f571e115248> hook = <_HookCaller 'pytest_runtest_setup'> methods = [<_pytest.vendored_packages.pluggy.HookIm Output exceeded 6164480 bytes, remaining output has been truncated command interrupted, attempting to kill process killed by signal 9 program finished with exit code -1 elapsedTime=4231.017581